A variable declared in the for loop control can be used after the loop exits.
查看答案
The following loop displays _______________.for (int i = 1; i <= 10; i++) {System.out.print(i + " ");i++;}
A. 1 2 3 4 5 6 7 8 9
B. 1 2 3 4 5
C. 2 4 6 8 10
D. 1 3 5 7 9
Is the following loop correct?for (; ; );
A. No
B. Yes
What is the output of the following fragment?for (int i = 0; i < 15; i++) {if (i % 4 == 1)System.out.print(i + " "); }
A. 1 5 9 13 16
B. 1 4 8 12
C. 1 3 5 7 9 11 13 15
D. 1 5 9 13
Analyze the following statement:double sum = 0;for (double d = 0; d < 10;) {d += 0.1;sum += sum + d;}
A. The program has a compile error because the adjustment is missing in the for loop.
B. The program compiles and runs fine.
C. The program has a compile error because the control variable in the for loop cannot be of the double type.
D. The program runs in an infinite loop because d<10 would always be true.