Nested Loop Tally
A program calculates the total number of times an inner statement executes within nested loops.
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 = i; j < 3; j++) {
count++;
}
}
System.out.println(count);
}
}
A
7
B
9
C
5
D
6
Question Leaderboard
Not enough data yet to show leaderboard.
