← Quiz: Java Control Flow: all 10 questions
Quiz: Java Control Flow · Question 3 of 10
What does this print? (code)
What does this print?
public class Main {
public static void main(String[] args) {
int n = 2;
switch (n) {
case 1: System.out.print("one ");
case 2: System.out.print("two ");
case 3: System.out.print("three ");
}
}
}
- A.two
- B.two three
- C.one two three
- D.three
Answer & explanation
Correct answer: two three
Without break, execution falls through from case 2 into case 3.
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 →