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

In this Java program, we will learn how to find the GCD of two numbers using Java.  GCD (Greatest Common...
  • Java
  • December 3, 2024
In this Java Program, you’ll learn how to swap two numbers using the Java programming language.  How to Swap Two...
  • Java
  • December 2, 2024
In this Java program , we will learn how to Find Largest Element in an Array in your Java program.   How to Find Largest Element...
  • Java
  • December 2, 2024