Java Program to Check Leap Year

In this article we will write a java program to check if given year is leap year or not. In other words how to find leap year in java ?

For year to be leap year the first condition is that it must be divisible by 4. If its a century year i.e 100,200,300 etc then it must be divisible by 400 as well.


Lets see Java program which will check if a given year is leap year in Java.


public class FindLeapYear {

	public static void main(String[] args) {
		
		int year = 2020;
		boolean isLeapYear = false;
		
		if (year % 4 == 0) {
			
			if (year % 100 == 0) {
				
				if (year % 400 == 0) {
					isLeapYear = true;
				} else {
					isLeapYear = false;
				}
				
			} else {
				isLeapYear = true;
			}
			
		}
		
		if (isLeapYear) {
			System.out.println(year + " is a leap year");
		} else {
			System.out.println(year + " is NOT a leap year");
		}
		
	}

}

Out of this program is - 
2020 is a leap year

0 Comments