Java Reference
In-Depth Information
Answers to Review Questions
1.
if/else and switch.
2.
while, do/while, and for loops.
3.
False, because one of the two expressions is false.
4.
True, because one of the two expressions is true.
5.
Only 32-bit integer types can be used in a switch statement, so a, b, and e are the
correct answers.
6.
True.
7.
That is an infinite loop because the value of k does not change. The output will be the
number 20 printed over and over until the program is terminated.
8.
Because the case of 15 does not contain a break, the output is “point is 15” followed
by “point is 15 or 30.”
9.
Again, because the case of 40 does not contain a break, the output is “point is 40” and
“Invalid point.”
10.
Because rate is 1.5, the price is 15 * 15, which is 22.5. The output is 22.5.
11.
If rate is -0.75, none of the if expressions will evaluate to true, and price will remain 0.
The output is 0.
12.
The loop will execute only one time. The value of b will be 2.
13.
The loop outputs the multiples of 5, starting at 95 and ending at 0. The output is:
95
90
85
80
75
70
65
60
55
50
45
40
35
30
25
20
15
10
5
0
Search WWH ::




Custom Search