Chp03 CheckPointAnswers
Chp03 CheckPointAnswers
2.
true
false
true
true
false
4.
if (y > 0)
x = 1;
5.
6.
7.
If number is 30,
(a) displays
30 is even
30 is odd
(b) displays
30 is even
If number is 35,
(a) displays
35 is odd
(b) displays
35 is odd
true false
x>2
true
int z = x + y;
System.out.println("z is " + z);
11. a, c, and d are the same. (B) and (C) are correctly indented.
12.
13.
Both are correct. (b) is better.
14 is even
15 is multiple of 5
30 is even
30 is multiple of 5
14 is even
15 is multiple of 5
30 is even
(d) (int)(Math.random() * 2)
17. Yes
false
false
(x > 0) || (x < 0)
true
(x != 0) || (x == 0)
true
(x >= 0) || (x < 0)
true
(x != 1) == !(x == 1)
true
19. (a) (x > 1) && (x < 100) (b) (num > 1) && (num < 100) || num < 0
20. (a) (x – 5> < 4.5 && (x – 5) > -4.5 (b) (x – 5> > 4.5 && (x – 5) < -4.5
21. x>y>0
incorrect
x = y && y
incorrect
x /= y
correct
x or y
incorrect
x and y
incorrect
(x != 0) || (x = 0)
Incorrect on x = 0
22.
Yes
23.
24.
(x + y < z) is true
(x + y < z) is true
26.
29. Switch variables must be of char, byte, short, or int data types. If a break statement is not
used, the next case statement is performed. You can always convert a switch statement to an
equivalent if statement, but not an if statement to a switch statement. The use of the switch
statement can improve readability of the program in some cases. The compiled code for the
switch statement is also more efficient than its corresponding if statement.
30. y is 2.
x = 3; y = 3;
if (x + 3 == 6) {
y = 1;
y += 1;
31. x is 17
switch (a) {
case 1: x += 5; break;
case 4: x += 34;
a is 1
x += 5; break
a is 2
x += 10; break
a is 3
x += 16; break
a is 4
x += 34; break
33. Sorted
34.
35.
(A)
if (x > 10)
score = 3 * scale;
else
score = 4 * scale;
(B)
(C)
if (number % 3 == 0)
System.out.println(i);
else
System.out.println(j);
36. (int)(Math.random() * 2) == 0 ? -1 : 1.
38. True