Created
September 1, 2019 10:09
-
-
Save arindamroynitw/b7c80d0d873e2e6899d6068013f8ec70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static java.util.Calendar.*; | |
public class NewSwitch { | |
public static void main(String[] args) { | |
int numberOfDays = getNumberOfDays(MARCH); | |
System.out.println("The number of days in this month are " + numberOfDays); | |
} | |
public static int getNumberOfDays(int monthNum) { | |
return switch (monthNum) { | |
case JANUARY, MARCH, MAY, JULY, AUGUST, OCTOBER, DECEMBER -> 31; | |
case APRIL, JUNE, SEPTEMBER, NOVEMBER -> 30; | |
case FEBRUARY -> 28; //assuming nin leap year for simplicity | |
default -> throw new IllegalArgumentException("Not a month"); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment