Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
hard Solved by 2 students

Pattern Generation

Mark
< Prev
Next >

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

Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|