Leap year program in JAVA – To find whether a year is a leap or not is a bit tricky. We assume that if a year number is completely divisible by 4 is a leap year. But it is not the only subtle case. A year is a leap year if −
- 1. It is evenly divisible by 100
- 2. If it is divisible by 100 as well as by 400
- 3. Despite this, all other years evenly divisible by 4 are leap years.
Let’s discuss the algorithm:
1. Take an integer variable for the year
- Now assign a value to the variable.
- Check whether the year is divisible by 4 but not 100, DISPLAY “leap year”
- Else check if the year is divisible by 400, DISPLAY “leap year”
- Otherwise, DISPLAY “not leap year”