Page 504 - Introduction to Programming with Java: A Problem Solving Approach
P. 504
470
Chapter 11 Type Details and Alternate Coding Mechanisms
e)
f)
a - (b = 4) % 7 ⇒ 2 - 4 % 7⇒
2-4 ⇒
-2
b = x = 23 ⇒
b = 23.0 ⇒
compilation error (because the float 23.0 cannot be assigned to the int b without a cast operator)
14. Will it evaluate expr2?
a) No. Since the left side of the || operator is true, short-circuit evaluation will cause the right side of
the || operator (expr2) to be ignored (since the result of the entire expression will evaluate to true
regardless of expr2’s value).
b) Yes.
15. Assuming:
int a = 2;
boolean flag = true;
a < 3 || flag && !flag ⇒ 2 < 3 || true && !true ⇒ 2 < 3 || true && false ⇒ true || true && false ⇒
true (short circuit evaluation dictates “true or anything” evaluates to true)
Apago PDF Enhancer
16. It prints nothing because, due to the empty statement, the while loop header executes repeatedly in an infinite loop.
17. True. Normally, you should avoid using break other than in switch statements.
18. The code fragment generates an infinite loop because the for loop header’s missing second component is
true by default. The output is:
0 2 4 6 ...
19. The hexadecimal symbol for the decimal number 13 is either d or D.
20. False. They are the same only in the range from 0x00 to 0x7F.