Showing posts with label Java Program to Check Leap Year or Not. Show all posts
Showing posts with label Java Program to Check Leap Year or Not. Show all posts
on Leave a Comment

Java Program to Check Leap Year or Not

This java program checks whether a year is leap year or not. Leap year is a year comes after every four year containing 366 days including 29 February as an intercalary day.

A year is a leap year if:

1. Year is divided by 4 but not by 100.
2. Century year (1600, 2000 etc) is divided by 400 and 100.

Java Program to Check Leap Year or Not

import java.util.Scanner;

public class CheckLeapYear
{
    public static void main(String args[])
    {
       int year;
       Scanner read = new Scanner(System.in);
    
       System.out.print("Enter Year : ");
       year = read.nextInt();
    
       if((year%400==0)||(year%100!=0 && year%4==0))
        System.out.println(year+" is a Leap Year.");
       else
        System.out.println(year+" is not a Leap Year.");
    }
}

Output 1:

Enter Year : 2016
2016 is a Leap Year.

Output 2:

Enter Year : 1998
1998 is not a Leap Year.