Page 503 - Introduction to Programming with Java: A Problem Solving Approach
P. 503
Review Question Solutions
1. byte8bits,short16bits,int32bits,long64bits
2. 1.602E-19 or 1.602e-19
3. float precision 6 digits, double precision 15 digits
4. The basic ASCII character set describes 128 different characters.
5. To convert uppercase to lowercase, add 32. To go the other way, subtract 32.
6. System.out.println((long) C); // (int) isn’t big enough!
7. This statement is OK:
float price = 66;
8. This statement generates a compile-time error because it’s illegal to convert between numeric values and boolean values:
boolean done = (boolean) 0;
9. This statement generates a compile-time error because floating point constants are double by default: float price = 98.1;
10. z’s value is 4. The first decrement uses prefix mode so x is first decremented to 2, then 2 is assigned into z. The second decrement uses postfix mode so x is decremented after its value of 2 is added to z.
Apago PDF Enhancer
11. w = x = y = z;oranyothersequencethathaszontheright.
12. The switch controlling expression evaluates to 'M'
13. Expression-evaluation practice:
a) a + ( 2 2 + 2 + 4.5
b) 7 + 7 + 7 + 7 + 7 +
12
c) a * 2 * 2 *
25 / (x + 2)⇒
+ 25 / (8.0 + 2) ⇒ 25 / 10.0 ⇒
2.5 ⇒
a * --b / 2⇒ 2 * --6 / 2⇒ 2 * 5 / 2⇒
10 / 2 ⇒
5⇒
--b / 6 ⇒ --6 / 6 ⇒
5 / 6⇒
Review Question Solutions 469
d)
a
+ b++ ⇒
+ 6 (b is updated to 7 after its value is accessed) ⇒
10 / 6 ⇒ 1
2
8