Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int daysInMonth(int month, int year) {
- return switch (month) {
- case 2 -> isLeapYear(year) ? 29 : 28;
- case 4, 6, 9, 11 -> 30;
- default -> 31;
- }
- }
- private static boolean isLeapYear(int year) {
- return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment