Nested Increment
A program uses nested loops to increment a counter variable based on the outer loop iteration index.
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 = 1; i < 4; i++) {
for (int j = 0; j < i; j++) {
count++;
}
}
System.out.println(count);
}
}
A
6
B
3
C
5
D
9
Question Leaderboard
Not enough data yet to show leaderboard.
