Java Program To Check A Given Year Is Leap Year Or Not
Chapter:
Interview Programs
Last Updated:
14-07-2016 08:12:20 UTC
Program:
/* ............... START ............... */
public class JavaLeapYear {
public static void main(String args[]) {
int year = 2000;
// Flag to store the test result
boolean isLeapYear = false;
if (year % 400 == 0) {
isLeapYear = true;
} else if (year % 100 == 0) {
isLeapYear = false;
} else if (year % 4 == 0) {
isLeapYear = true;
} else {
isLeapYear = false;
}
// Output the test result
if (isLeapYear) {
System.out.println("Year " + year + " is a Leap Year");
} else {
System.out.println("Year " + year + " is not a Leap Year");
}
}
}
/* ............... END ............... */
Output
Notes:
-
A leap year is exactly divisible by 4 except for century years (years ending with 00). The century year is a leap year only if it is perfectly divisible by 400.
Tags
Leap Year, Java