Question 10
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
public class Main {
public static void main(String[] args) {
int day = 6;
switch (day) {
case 6 -> System.out.println("Saturday");
case 7: System.out.println("Sunday"); break;
default -> System.out.println("weekday");
}
}
}
- A day must be an enum
- B A switch must use either arrow (->) labels or colon (:) labels throughout; it cannot mix the two styles Correct
- C default cannot use ->
- D case 7 needs braces
Correct Answer: Option B
Pick one style – arrows are recommended.
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!