Skip to content
Marlbridge

AP® Computer Science A · Unit 1 · Topic 1.5

Casting and Range of Variables: Checklist (Computer Science A 1.5)

A self-check list for casting with (int) and (double), rounding doubles, the range of int, integer overflow and round-off error, linked to the guide and practice questions.

Work through the list without notes. If you cannot do a statement, follow its link, then come back. Guide = study guide; Practice = practice questions.

Understanding

  • I can explain that casting a double to an int truncates the digits after the decimal point. (Guide: “Casting a double to an int truncates”; Practice Question 1)
  • I can explain when an int is widened to a double automatically. (Guide: “Automatic widening”)
  • I can say what Integer.MAX_VALUE and Integer.MIN_VALUE hold and why an int has a limited range. (Guide: “The range of int”; Practice Question 4)
  • I can explain what integer overflow is and that it throws no exception. (Guide: “Integer overflow”; Practice Questions 4 and 8)
  • I can explain what a round-off error is and how using int values avoids it. (Guide: “Round-off error in double”; Practice Question 5)

Skills

  • I can evaluate expressions that contain (int) and (double), including truncation of negative values. (Guide: Worked example 2; Practice Questions 1 and 10)
  • I can place a cast so that a division keeps its fractional part. (Guide: Worked example 1; Practice Questions 2, 7 and 9)
  • I can round a non-negative or a negative double to the nearest int using a cast. (Guide: “Rounding to the nearest integer”; Practice Questions 3 and 7)
  • I can write an average or percentage expression that is correct for int variables. (Practice Questions 7 and 9)

Reasoning

  • I can explain why (double) (a / b) and (double) a / b differ. (Guide: “Where the cast goes matters”; Practice Questions 2 and 6)
  • I can recognise code where an int expression can overflow and describe what the result will be like. (Guide: Worked example 2; Practice Question 8)
  • I can explain why double avg = sum / count; can lose a fraction even though avg is a double. (Practice Question 9)

All ticked? Move on to the Topic 1.6 study guide, Compound Assignment Operators, or return to the course roadmap.

AP® and Advanced Placement® are trademarks registered by the College Board, which is not affiliated with, and does not endorse, this website. Marlbridge is an independent tuition provider. It is not an authorized AP course provider, an AP school or an exam centre, and these resources are not official College Board materials. Reading them or doing simulations does not meet the laboratory requirement of an AP science course.