🎙 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 8 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 <= 5; i++) {
            if (i % 2 == 0) continue;
            System.out.print(i);
        }
        System.out.println();
    }
}
  1. A.12345
  2. B.24
  3. C.1
  4. D.135
Answer & explanation

Correct answer: 135

continue skips the rest of the body for even numbers, so only 1, 3 and 5 are printed.

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 →