Answers for "java switch expression produce result"

0

java switch expression produce result

// Use the yield keyword to produce a result in a switch expression.

int result = switch (month) {
    case JANUARY, JUNE, JULY -> 3;
    case FEBRUARY, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER -> 1;
    case MARCH, MAY, APRIL, AUGUST -> {
        int monthLength = month.toString().length();
        yield monthLength * 4;
    }
    default -> 0;
};
Posted by: Guest on August-17-2021

Code answers related to "java switch expression produce result"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language