Java Reference
In-Depth Information
with the following:
System.out.printf("%.2f + %.2f = %.2f %n",
num1, num2, (num1 + num2));
15. 4 3 2 1
17. 0 3 8 15 24
19. Loop control variable: j
The initialization statement: j ¼ 1;
Loop condition: j < ¼ 10;
Update statement: j++
The statement that updates the value of s : s ¼ s + j * (j - 1);
21. 2 7 17 37 77 157
23. a. *
b. infinite loop
c. infinite loop
d. ****
e. ******
f. ***
25. The relationship between x and y is: 3 y ¼ x .
Output: x ¼ 19683, y ¼ 10
27. 0 - 24
25 - 49
50 - 74
75 - 99
100 - 124
125 - 149
150 - 174
175 - 200
29.
a. Both; b. do ... while ;c. while ;d. while
31.
In a pretest loop, the loop condition is evaluated before executing the body of the
loop. In a posttest loop, the loop condition is evaluated after executing the body of the
loop. A posttest loop executes at least once, while a pretest loop may not execute at all.
33.
(Assume that console is a Scanner object initialized to the standard input device.)
int num;
do
{
System.out.println("Enter a number less than 20 "
+ "or greater than 75: ");
num = console.nextInt();
}
while (20 <= num && num <= 75);
Search WWH ::




Custom Search