Guest User

Untitled

a guest
Aug 23rd, 2021
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.32 KB | None | 0 0
  1.  
  2. public static int daysInMonth(int month, int year) {
  3.       return switch (month) {
  4.         case 2 -> isLeapYear(year) ? 29 : 28;
  5.         case 4, 6, 9, 11 -> 30;
  6.         default -> 31;
  7.       }
  8.     }
  9.  
  10. private static boolean isLeapYear(int year) {
  11.    return year % 400 == 0 || (year % 4 == 0  && year % 100 != 0);
  12. }
Advertisement
Add Comment
Please, Sign In to add comment