import java.util.*; public class Months { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Month (1-12): "); int month = input.nextInt(); if (1 <= month && month <= 12) { System.out.print("Year: "); int year = input.nextInt(); int days = numDays(month, year); System.out.println("Number of days in month " + month + " is " + days); } else { System.out.println(month + " is not a valid month number"); } } // ------------------------------ public static int numDays(int month, int yr) { int days; if (month == 2) { // days = 28 + isLeapYear1(yr); days = 28; if (isLeapYear2(yr)) { days++; } } else if (month == 4) { days = 30; } else if (month == 6) { days = 30; } else if (month == 9) { days = 30; } else if (month == 11) { days = 30; } else { days = 31; } return days; } //--------------------------------------- public static int isLeapYear1(int year) { if (year % 400 == 0) { return 1; } else if (year % 100 == 0) { return 0; } else if (year % 4 == 0) { return 1; } else { return 0; } } //--------------------------------------- public static boolean isLeapYear2(int year) { if (year % 400 == 0) { return true; } else if (year % 100 == 0) { return false; } else if (year % 4 == 0) { return true; } else { return false; } } //-------------------------------------- public static boolean isLeapYear3(int yr) { return ((yr % 400 == 0) || (!(yr % 100 == 0) && (yr % 4 == 0))); } }