Page 675 - AP Computer Science A, 7th edition
P. 675

19. (A) Subtracting 0.5 from a negative real number and then truncating it produces the number correctly rounded to the nearest integer. Note that casting to an int truncates a real number. The expression in choice B is correct for rounding a positive real number. Choice C won’t round correctly. For example, −3.7 will be rounded to −3 instead of −4. Choices D and E don’t make sense. Why cast to double if you’re rounding to the nearest integer?


































































































   673   674   675   676   677