Java Program to Check Leap Year

Leap year is a year which is divisible by 4 and if a century year is a leap year then it must be divisible by 400.

Example: Java Program to Check a Leap Year

public class CheckLeapYear {

    public static void main(String[] args) {

        int year = 1900;
        boolean leap = false;

        if(year % 4 == 0)
        {
            if( year % 100 == 0)
            {
                // If year is divisible by 400, then that year is a leap year
                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

1900 is not a leap year.

Leave a Reply