AP Computer Science A · Lesson 1.5 · Unit 1 · CED topic 1.5

Casting and the range of variables

Name:   Date:  

1 Why this lesson matters

Read the opening paragraph and the "Required content" box on the lesson page. In your own words, explain each objective below.

5.A. Develop code to cast primitive values to different primitive types in arithmetic expressions and determine the value that is produced as a result.

5.B. Describe conditions when an integer expression evaluates to a value out of range.

5.C. Describe conditions that limit accuracy of expressions.

2 Casting with (int) and (double)

Read this section. In your own words, summarize the main idea.

3 The range of an int

Read this section. In your own words, summarize the main idea.

4 When a double is not exact

Read this section. In your own words, summarize the main idea.

5 Worked example

Read the "Worked example" box. Then, without looking back, try writing your own answer below.

Give the value and the type of each expression.

6 Exam focus: avoid this mistake

Read the "Exam focus" box, then restate it in your own words.

7 Sum it up

In two or three sentences, explain this lesson's main idea to someone who has not read it.