How to Check a Leap Year in Java


In this example, let’s us see how to determine if the given year is a leap year in Java.

Source Code

package com.beginner.examples;

public class LeapYearExample {

    public static void main(String[] args){
    	int year = 2019;
    	if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)// definition of leap year
        {
    		System.out.println(year + " is a leap year.");
		}
		else
		{
			System.out.println(year + " is not a leap year.");
		}
    }
}

Output:

2019 is not a leap year.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments