In this video, we will write a JAVA Program to Check whether an year is a leap year or not.
Conditions for leap years:
1. A year must be divisible by 400 then it is a leap year.
2. If the year is divisible by 100 then it is not a leap year.
3. Else if the year is divisible by 4 then is a leap year.
4. If all conditions are false then enter year is not leap year.
Example:
Input year: 2024
Output: Yes
Input year: 2022
Output: No
We use Conditional operators to check leap years.
Here, the user is provided the flexibility to enter the year of own choice as Scanner Class is imported here rest of the if-else blocks are also combined in a single statement to check if the input year is a leap year.
Java Program to Find if a Given Year is a Leap Year: https://www.geeksforgeeks.org/java-program-to-find-if-a-given-year-is-a-leap-year/