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
doubleto aninttruncates the digits after the decimal point. (Guide: “Casting a double to an int truncates”; Practice Question 1) - I can explain when an
intis widened to adoubleautomatically. (Guide: “Automatic widening”) - I can say what
Integer.MAX_VALUEandInteger.MIN_VALUEhold and why aninthas 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
intvalues 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
doubleto the nearestintusing 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
intvariables. (Practice Questions 7 and 9)
Reasoning
- I can explain why
(double) (a / b)and(double) a / bdiffer. (Guide: “Where the cast goes matters”; Practice Questions 2 and 6) - I can recognise code where an
intexpression 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 thoughavgis adouble. (Practice Question 9)
All ticked? Move on to the Topic 1.6 study guide, Compound Assignment Operators, or return to the course roadmap.