Pattern Generation
Nested for loops compare iteration indices to determine whether to print A or B.
What is printed when the following Java program is compiled and run?
public class QuestionTrace {
public static void main(String[] args) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
if (i == j) System.out.print("A");
else System.out.print("B");
}
}
}
}
A
BBAABB
B
AABABB
C
ABBBAB
D
ABABBB
Question Leaderboard
Not enough data yet to show leaderboard.
