Nested Iteration Count
A program tracks the total number of times an inner loop body is executed within a triangular nested structure.
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 < 3; i++) {
for (int j = 0; j <= i; j++) {
count++;
}
}
System.out.println(count);
}
}
A
6
B
3
C
12
D
9
Question Leaderboard
Not enough data yet to show leaderboard.
