In this article we will show you the solution of how to find leap year in java, the leap year is the year in which there are 366 days instead of 365. In order for a leap year to occur, it must satisfy either of the following constraints:

- A number that can be divided by 400 should be used
- In order for it to be divisible by four, it should not be divisible by 100

The Java language supports if-else blocks with appropriate conditions for identifying a leap year.

Similarly, Java provides a built-in method isLeap() for determining whether or not a year is a leap year. We will now discuss the idea of how to find leap years in java with an example.

## Step By Step Guide On How To Find Leap Year In Java :-

import java.io.*; public class TalkersCode{ public static void isLeapYear(int year) { boolean is_leap_year = false; if (year % 4 == 0) { is_leap_year = true; if (year % 100 == 0) { if (year % 400 == 0) is_leap_year = true; else is_leap_year = false; } } else is_leap_year = false; if (!is_leap_year) System.out.println(year + " : Non Leap-year"); else System.out.println(year + " : Leap-year"); } public static void main(String[] args) { isLeapYear(2000); isLeapYear(2002); } }

- The program begins with importing necessary classes/files.
- The class is defined with the name 'TalkersCode'.
- A method named 'isLeapYear' is defined that takes an integer value 'year' as a parameter.
- A boolean variable 'is_leap_year' is declared with the initial value 'false'. This variable is used to store whether a given year is a leap year or not.
- The method checks whether the given year is divisible by 4 using the modulo operator.
- If the year is divisible by 4, the boolean variable 'is_leap_year' is set to true.
- The method checks whether the given year is a century or not. A century year is a year that is divisible by 100.
- If the given year is a century year, the method checks whether it is divisible by 400. If it is divisible by 400, then it is a century leap year. The year is not a leap year if the conditions are not met.
- If the given year is not a century year, the method does not check the divisibility by 400.
- If the given year is not divisible by 4, then the boolean variable 'is_leap_year' is set to false.
- The method checks the final value of the boolean variable 'is_leap_year'. If it is false, then the year is a non-leap year, and if it is true, it is a leap year.
- The method prints the year and whether it is a leap year or not on the console.
- The main method is defined that calls the 'isLeapYear' method twice with different values.
- The first call is made with the year 2000, which is a leap year because it is a century leap year.
- The second call is made with the year 2002, which is not a leap year.
- The program execution ends.

## Conclusion :-

As a result, we have successfully learned how to find leap year in java with an example.

The term leap year refers to years that are either divisible by 400 or by 4, and not by 100. The answer to this question can be found by using simple if-else blocks.

In an elegant manner, ternary operators can be used to represent if-else logic.

In order to modularize the code, the entire if-else logic can be moved to a method that determines whether the input year is leap year.

I hope this article on how to find leap year in java helps you and the steps and method mentioned above are easy to follow and implement.