Q:

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

0

Java Program to check whether the input year is leap or not using if else statement.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.");
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now