0

Java switch expression

I dont get this @_@??? it's not working int dayType=switch(day){ //illegal start of expression switch case 1, 2, 3, 4, 5 -> "working day"; case 6, 7 -> "weekend"; default -> "invalid day"; };

29th Jun 2021, 7:55 AM
Mcneil
Mcneil - avatar
1 Answer
+ 3
The return type of your switch expression doesn't match the expected type. dayType is an int, but a String is returned. int day = 3; String dayType = switch(day) { case 1, 2, 3, 4, 5 -> "working day"; case 6, 7 -> "weekend"; default -> "invalid day"; }; System.out.println(dayType);
29th Jun 2021, 8:09 AM
ChaoticDawg
ChaoticDawg - avatar