public class LeapYear {
public static void main(String[] args) {
int year = Integer.parseInt(args[0]);
boolean isLeapYear;
// divisible by 4
isLeapYear = (year % 4 == 0);
// divisible by 4 and not 100
isLeapYear = isLeapYear && (year % 100 != 0);
// divisible by 4 and not 100 unless divisible by 400
isLeapYear = isLeapYear || (year % 400 == 0);
System.out.println(isLeapYear);
}
}
/*************************************************************************
* Execution: java LeapYear N
*
* Prints true if N corresponds to a leap year, and false otherwise.
* Assumes N >= 1582, corresponding to a year in the Gregorian calendar.
*
* % java LeapYear 2004
* true
*
* % java LeapYear 1900
* false
*
* % java LeapYear 2000
* true
*
*************************************************************************/
Not Satisfied ? Just search & get the result
Related posts:
- c program to find whether a given year is leap year or not
- Java program – Quadratic formula
- Java program – Integer multiplication and division
- c program to convert given number of days to a measure of time given in years, weeks and days. For example 375 days is equal to 1 year 1 week and 3 days
- C program to find the number of integers divisible by 5 between the given range N1 and N2, where N1 < N2 and are integers. Also find the sum of all these integer numbers that divisible by 5 and output the computed results
