Nested Loop Iterations
A program performs nested loops where an inner loop counter is incremented based on a conditional statement to track total executions.
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 <= 3; i++) {
for (int j = 1; j <= i; j++) {
if ((i + j) % 2 == 0) {
count++;
}
}
}
System.out.print(count);
}
}
A
3
B
6
C
5
D
4
Question Leaderboard
Not enough data yet to show leaderboard.
