Start Coding Now
🌱 Beginner Programsbeginner1 methods

Check Leap Year in Java

Program to check if a year is a leap year or not.

Last updated: 11 January 2026

Method 1: Using If-Else

Checking divisibility by 4, 100, and 400.

public class LeapYear {
    public static void main(String[] args) {
        int year = 2024;
        boolean leap = false;

        if (year % 4 == 0) {
            if (year % 100 == 0) {
                if (year % 400 == 0)
                    leap = true;
                else
                    leap = false;
            } else
                leap = true;
        } else
            leap = false;

        if (leap)
            System.out.println(year + " is a leap year.");
        else
            System.out.println(year + " is not a leap year.");
    }
}
Output:
2024 is a leap year.

Explanation

A year is a leap year if divisible by 4, except for end-of-century years, which must be divisible by 400.

Frequently Asked Questions

Try This Program

Copy this code and run it in our free online Java compiler.

Open Java Compiler