Please enable JavaScript to use CodeHS

AP Computer Science A (Nitro)

Lesson 1.6 Casting and Ranges of Variables

Description

In this lesson, students will learn how to change the data type of a value through the process of casting. They will also use casting to help round double values to the closest integer value. Students will explore the range of variables allowed in Java and understand integer overflow when a value outside of this range is attempted. This lesson corresponds with AP Computer Science A topic 1.5.


Objective

Students will be able to:

  • Evaluate arithmetic expressions that use casting
  • Understand that integer values in Java are stored using a finite amount (4 bytes) of memory. Therefore, an int value must be in the range from Integer.MIN_VALUE to Integer.MAX_ VALUE inclusive
  • Understand when an expression evaluates to an int value outside of the allowed range, an integer overflow occurs
  • Recognize and use implicit casting
  • Use casting to round to the nearest integer