{
public static void main(String args[])
{
int counter = 0;
for (int j = 10; j > 0; –j)
++counter;
}
}
Which of the following statements is true?
a. The value of counter will be different at the end of each for loop for each class.
b. The value of j will be the same for each loop for all iterations
c. Both (a) and (b) are true.
d. Neither (a) nor (b) is true.
5.4 Q1: Which of the following for-loop headers results in equivalent numbers of iterations:
A. for (int q = 1; q <= 100; q++)
B. for (int q = 100; q >= 0; q—)
C. for (int q = 99; q > 0; q -= 9)
D. for (int q = 990; q > 0; q -= 90)
a. A and B.
b. C and D.
c. A and B have equivalent iterations and C and D have equivalent iterations.
d. None of the loops have equivalent iterations.
5.4 Q2: Which of the following will count down from 10 to 1 correctly?
a. for (int j = 10; j <= 1; j++)
b. for (int j = 1; j <= 10; j++)
c. for (int j = 10; j > 1; j—)
d. for (int j = 10; j >= 1; j—)
5.4 Q3: Which of the following is equivalent to this code segment?
int total = 0;
for (int i = 0; i <= 20; i += 2)
total += i;
a. int total = 0;
for (int i = 20; i < 0; i += 1)
total += i;
b. int total = 0;
for (int i = 0; i <= 20; total += i, i += 2);