🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Control Flow: all 10 questions

Quiz: Java Control Flow · Question 9 of 10

What does this print? (code)

What does this print?

public class Main {
    public static void main(String[] args) {
        for (int i = 1; i <= 3; i++) {
            for (int j = 1; j <= 3; j++) {
                if (j == 2) break;
                System.out.print(i + "" + j + " ");
            }
        }
        System.out.println();
    }
}
  1. A.11 21 31
  2. B.11
  3. C.11 12 13
  4. D.11 12 21 22 31 32
Answer & explanation

Correct answer: 11 21 31

break leaves only the inner loop. Each outer round prints j = 1 and then stops the inner loop at j = 2.

Can you get the rest right without peeking?

Take the timed Quiz: Java Control Flow quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →