Question 1
Back to Exercise
What is the output of the following Java program?
public class Main {
public static void main(String[] args) {
int x = 2;
switch (x) {
case 1: System.out.print("one ");
case 2: System.out.print("two ");
case 3: System.out.print("three ");
default: System.out.print("other ");
}
System.out.println();
}
}
- A two three other Correct
- B two
- C two other
- D one two three other
Correct Answer: Option A
Execution starts at case 2 and falls through every following label, including default.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!