Java Program to check given year is leap year or not

Java Program to check given year is leap year or not

In this tutorial, we will be learning to write a leap-year program in Java. A leap year is a year that has 29 days in February and 366 days in a year.

For example:

2004 and 2008 are the leap year because it has a total of 366 days in the year.

1900 is not a leap year because it has only 365 days and February has 28 days.

Leap Year Program in Java


import java.util.*;
public class Main
{
    public static void main(String[] args) {
        int year;
        System.out.println("Leap Year Program in Java" );
        Scanner sc = new Scanner(System.in);
        System.out.println("Give the Year in input:");
        year= sc.nextInt();
        if (year % 400 == 0) {
            System.out.println("Given year "+ year +" is a leap year.");
        }
        else if (year % 100 == 0) {
            System.out.println("Given year "+ year +" is not a leap year.");
        }
        else if (year % 4 == 0) {
            System.out.println("Given year "+ year +" is a leap year.");
        }
        else {
            System.out.println("Given year "+ year +" is not a leap year.");
        }
    }
}

Output

Leap Year Program in Java
Give the Year in input:
2004
Given year 2004 is a leap year.