Invalid syntax

Report a typo

Which of the following case statements is invalid?

int numberOfHamburgersToEat = switch (howHungryAmI) {

    case 1, 2, 3 -> 0;                  // A

    case 4, 5, 6 -> {                   // B
        yield 1;
    }

    case 7, 8, 9 -> {                   // C
        System.out.println(2);
        yield 2;
    }

    case 10 -> {                        // D
        numberOfHamburgersToEat = 3;    
        break;
    }

    default -> throw new Exception("The number must be between 1 and 10");
};
Select one option from the list
___

Create a free account to access the full topic