HomeJavaJava Program to Check for Leap Year

Java Program to Check for Leap Year

In this Java program, you’ll learn how to Check for a leap year using the Java programming language

How to Check for a Leap Year? 

In this program, we’ll learn how to check for a leap year through JAVA program. 

There are some tricks to find whether a year is leap or not  

If a year is evenly divisible by 4, or it is evenly divisible by 100 and the last trick is if the year is divisible by 100 then it should also divisible by 400. 

RUN CODE SNIPPET
import java.util.Scanner; 

public class Main { 

   public static void main(String[] args){ 

      int year; 

      System.out.println("Enter a Year : "); 

      Scanner sc = new Scanner(System.in); 

      year = sc.nextInt(); 

      if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) 

         System.out.println("The Specified year is a leap year"); 

      else 

         System.out.println("The Specified year is not a leap year"); 

   } 

}

OUTPUT 

Enter a Year: 2002 

The Specified year is not a leap year.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Java is a popular programming language that is used to develop a wide range of applications. If you are a...
  • Java
  • March 6, 2023
Java is a programming language and computing platform that is used to create various types of applications. It is used...
  • Java
  • March 6, 2023
In this post, you’ll learn how to download and install JUnit in Eclipse so that you can use in your...
  • Java
  • October 9, 2022