Java

Program to check whether the input year is leap or not?

Program to check whether the input year is leap or not?
import java.util.Scanner;
public class demo1 {

    public static void main(String[] args) {

    	int year;
    	Scanner n = new Scanner(System.in);
    	System.out.println("Enter any Year:");
    	year = n.nextInt();
    	n.close();
        boolean LeapYear = false;

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

        if(LeapYear==true)
            System.out.println(year + " is a Leap Year.");
        else
            System.out.println(year + " is not a Leap Year.");
    }
}
Nikhil Juneja

Passionate software developer and technical contributor at TutorialsLink.