Leap Year Program in Java

In this example, You learn about leap year program in Java

Here you learn Java program for leap year, You are given a year and the task of the program to find given year is a leap year or not.

Java Leap Year Program

import java.util.Scanner;

public class leapYear{
    public static void main(String[] args) {

        try (Scanner scanner = new Scanner(System.in)) {
            System.out.print("Enter a Year:");
            int year = scanner.nextInt();
            boolean isLeap = false;
            if (year % 4 == 0) {
                if (year % 100 == 0) {
                    if (year % 400 == 0)
                        isLeap = true;
                    else
                        isLeap = false;
                } else
                    isLeap = true;
            } else {
                isLeap = false;
            }

            if (isLeap == true) {
                System.out.println(year + " is a Leap Year.");
            } else {
                System.out.println(year + " is not a Leap Year.");
            }
        }
    }
}
Output

  Enter a Year:1900
  1900 is not a Leap Year.
You have any problem in the above leap year program in Java. Do not hesitate and write your problem in the comment box. I will support your problem

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form