Nested Loop Accumulation
A nested loop structure increments a counter for every iteration performed in the inner loop.
What is printed when the following Java program is compiled and run?
public class QuestionTrace {
public static void main(String[] args) {
int count = 0;
for (int i = 0; i < 4; i++) {
for (int j = i; j < 4; j++) {
count++;
}
}
System.out.print(count);
}
}
A
16
B
12
C
10
D
8
Question Leaderboard
Not enough data yet to show leaderboard.
