A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Java program to check whether year is Leap year or not
Q:

Java program to check whether year is Leap year or not

0

Java program to check whether year is Leap year or not

All Answers

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

Check Leap Year using Java Program

//Java program to check whether year is Leap year or not.
 
import java.util.*;
 
class LeapYear
{
    public static void main(String []s)
    {
        int year;
        Scanner sc=new Scanner (System.in);
         
        try
        {
             
            System.out.print("Enter year:");
            year=sc.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.");
        }
        catch (Exception Ex)
        {
            System.out.println("Oops ... : " + Ex.toString());
        }
         
    }
}

Output

    Complie 	:	javac LeapYear.java
    Run		:	java LeapYear
    Output
    First Run:
    Enter year:2000
    2000 is a Leap Year.

    Second Run:
    Enter year:2100
    2100 is not a Leap Year.

    Third Run:
    Enter year:2004
    2004 is a Leap Year.

    Fourth Run:
    Enter year:2005
    2005 is not a Leap Year.

 

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

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now