LearnFrenzy
Sign in Take a free test

Control Flow Statements · Find the Error · Question 10

Error: mixing arrow and colon cases Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

Main.java
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links