java switch expression produce result

Solutions on MaxInterview for java switch expression produce result by the best coders in the world

showing results for - "java switch expression produce result"
Lee
28 Feb 2019
1// Use the yield keyword to produce a result in a switch expression.
2
3int result = switch (month) {
4    case JANUARY, JUNE, JULY -> 3;
5    case FEBRUARY, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER -> 1;
6    case MARCH, MAY, APRIL, AUGUST -> {
7        int monthLength = month.toString().length();
8        yield monthLength * 4;
9    }
10    default -> 0;
11};
similar questions
queries leading to this page
java switch expression produce result