LeapYear.java

LeapYear.java

Below is the syntax highlighted version of LeapYear.java.


/******************************************************************************
 *  Compilation:  javac LeapYear.java
 *  Execution:    java LeapYear year
 *  
 *  Prints true if year corresponds to a leap year, and false otherwise.
 *  Assumes year >= 1582, corresponding to a year in the Gregorian calendar.
 *
 *  % java LeapYear 2004
 *  true
 *
 *  % java LeapYear 1900
 *  false
 *
 *  % java LeapYear 2000
 *  true
 *
 ******************************************************************************/

public class LeapYear { 
    public static void main(String[] args) { 
        int year = Integer.parseInt(args[0]);
        boolean a = (((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0);
        boolean b = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
        boolean c = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
        boolean d = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
        boolean e = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
        System.out.println(e);
    }
}



 

posted @ 2020-10-23 18:58  小树木  阅读(176)  评论(0编辑  收藏  举报