HW3.11

时间:2023-12-19 09:29:32

HW3.11

 import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);

         System.out.print("Enter the month: ");
         String month = input.nextLine();
         System.out.print("Enter the year: ");
         int year = input.nextInt();

         input.close();

         int days;

         if(month.equals("April") || month.equals("June") || month.equals("September") || month.equals("November"))
             days = 30;
         else if(month.equals("February"))
             days = 28;
         else
             days = 31;

         boolean isLeapYear = false;
         if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
             isLeapYear = true;

         if(isLeapYear && days == 28)
             days++;

         System.out.println(month + " " + year + " has " + days + " days");
     }
 }

相关文章