Question 1 of 10
In this header, which part executes only once?
for (int step = 0; step < 6; step++) {
System.out.print(step);
}
- A. int step = 0
- B. step < 6
- C. step++
- D. the loop body
In this header, which part executes only once?
for (int step = 0; step < 6; step++) {
System.out.print(step);
}
A descending counter feeds a sum. What text does this Java code display?
int sum = 0;
for (int d = 3; d >= 1; d--) {
sum += d;
}
System.out.print(sum);
Even wagon IDs are printed. What text does this Java code display?
for (int w = 2; w < 8; w += 2) {
System.out.print(w);
}
An accumulator is printed after each add. What text does this Java code display?
int acc = 1;
for (int i = 0; i < 3; i++) {
acc += i;
System.out.print(acc);
}
Which while loop is equivalent to this for loop?
for (int k = 5; k > 1; k--) {
System.out.print(k);
}
A growth log prints the loop control variable, then its value after the loop. What text does this Java code display?
int n;
for (n = 1; n < 20; n *= 2) {
System.out.print(n);
}
System.out.print("|" + n);
A crate counter decreases once per counted trip. What text does this Java code display?
int c = 9;
for (int i = 1; i <= 4; i++) {
c--;
}
System.out.print(c);
A gear ratio doubles by adding the variable to itself. What text does this Java code display?
int g = 2;
for (int t = 1; t <= 3; t++) {
g += g;
}
System.out.print(g);
A skipped header test is used on purpose. What text does this Java code display?
int z = 4;
for (int i = 10; i < 10; i++) {
z *= 2;
}
System.out.print(z);
How many times does this body run?
int count = 0;
for (int i = 1; i < 13; i += 3) {
count++;
}
System.out.print(count);