Days P5716 month

Meaning of the questions: Enter a year and a month to determine the year for a few days this month to consider a leap year

Note: There are 31 days Otsuki 135781012 Satsuki 30 days with a 469,102-average special February 28 days, 29 days leap year

          Analyzing conditions are leap year is a leap year divisible by 400, or divisible by 4, can not be divisible 100

        Function to define a month, then use the switch statement, can play a large monthly output is still Satsuki

       Then define a function of determining whether a leap year

     Finally, the output function

Import . Classes in java.util * ;
 public  class the Main {
     Private  static  int Day ( Boolean isLeapYear, int month The) // define a function for month 
    {
         Switch (month The) 
        { 
            Case . 1 :
             Case . 3 :
             Case . 5 :
             Case . 7 :
             Case . 8 :
             Case 10 :
             Case 12 is :
                 return 31 is;
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;
            case 2:
                if(isLeapYear)
                {
                    return 29;
                }
                else
                {
                    return 28;
                }
                default:
                    return -1;
        }
    }
    private static Boolean LeapYear ( int year) // definition of a function is a leap year judgment 
    {
         IF (400% year == 0 ) 
        { 
            return  to true ; 
        } the else  IF (100% year == 0 ) 
        { 
            return  to false ; 
        } the else  IF (year == 0. 4% ) 
        { 
            return  to true ; 
        } the else 
        { 
            return  to false ; 
        } 
    } 
public  static  voidmain (String [] args) {
         // the TODO method of automatically generating stubs 
     Scanner in = new new Scanner (the System.in);
      int year = in.nextInt ();
      int month The = in.nextInt (); 
     System.out.println (Day (LeapYear (year), month The)); 
  } 
}

 

Guess you like

Origin www.cnblogs.com/coke-/p/12644198.html