Java Reference
In-Depth Information
30. 2.0 1.5 1.0 0.5
31. n = 10;
while (n > 0)
{
System.out.println("Hello " + n);
n = n - 2;
}
32. The output is 1024 10 . The second number is the log to the base 2 of the first
number. (If the first number is not a power of 2, then only an approximation to
the log base 2 is produced.)
33. The output is 1024 1 . The semicolon after the first line of the for loop is probably
a pitfall error.
34. The output is too long to reproduce here. The pattern is as follows:
1 times 10 = 10
1 times 9 = 9
.
.
.
1 times 1 = 1
2 times 10 = 20
2 times 9 = 18
.
.
.
2 times 1 = 2
3 times 10 = 30
.
.
.
35. a. A for loop
b. and c. Both require a while loop because the input list might be empty. (A for
loop also might work, but a do-while loop definitely would not work.)
36. This is an infinite loop. The first few lines of output are
10
12
16
19
21
37. This is an infinite loop. The first few lines of output are
n == 1
limit == 10;
n == 2
limit == 3
n == 3
Search WWH ::




Custom Search