codescracker


java

Java Program to Check Leap Year or Not



« Previous Program Next Program »


Check Leap Year or Not

To check whether the input year is a leap year or not a leap year in Java Programming, you have to ask to the user to enter the year and start checking for the leap year.

Java Programming Code to Check Leap Year or Not

Following Java Program ask to the user to enter the year to check whether it is a leap year or not, then display it on the screen:

/* Java Program Example - Check Leap Year or Not */
		
import java.util.Scanner;

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

When the above Java Program is compile and executed, it will produce the following output. Above Java Programming Example Output (for leap year):

Java Program check leap year

Above Java Programming Example Output (for not leap year):

check leap year in java

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test