Leap Year Program in Java Using If Else

Leap Year Program in Java Using If Else is software, written in the Java programming language, will show whether the year is a leap year or not. This bundle contains a set of basic Java programs for beginners. There are 366 days in a year, with an intercalary day on February 29th every four years. 

Reason Behind the Leap Year Program in Java

Because a planet’s orbit around the Sun (year) and spin on its axis (day) are not precisely aligned, leap years occur.

Almost every other planet in our solar system is the same way. On Mars, for example, leap years outnumber normal years!

Why Leap Year is Calculated for Every Fours in February

The leap day is a day that comes every four years and is known as February 29.

Because the Earth does not circle the sun in exactly 365 days, this day is added to the calendar in leap years as a correction measure. 

The Julian calendar, which was initially used by the Romans, was modified into the Gregorian calendar.

Leap Year Definition

A year of 366 days and an intercalary day on February 29th that occurs every four years. 2020 is a leap year, with 366 days.

Every four years, we add an additional day to our calendars, February 29. It’s a leap year if the number is divisible by four.

According to the proleptic calendar system guidelines, the isLeap() method of the Year class in Java is used to determine if this Year object is a leap year or not.

If a year has 366 days, it is considered a leap year.

A year is a leap year if it is divisible by four, according to the principles of the proleptic calendar system.

If Else Statement in Java

The conditional statements in Java are as follows:

If a particular condition is true, use if to specify a block of code to be run. 

If the same condition is false, use otherwise to define a block of code to run.

If the initial condition is false, use else if to provide a new condition to test.

Leap Year Program in Java Using If Else

import java.util.Scanner;
public class Main
public static void main(String[] args)
int year;
System.out.println("Enter the year");
Scanner sc = new Scanner(System.in);
year = sc.nextInt();
if (((year % 4 == 0) && (year % 100!= 0)) 
|| (year%400 == 0))
System.out.println("it is a leap year");
System.out.println("it is not a leap year");

It is not a leap year