I was writing a code to check for a leap year | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I was writing a code to check for a leap year

But its more complicated than i thought. Give below are condiotions for a leap year and non leap year i came across. But i don't fully understand it... please give me a more precise condition for both years(leap/ non leap) 1) if the year is evenly divisible by 400, then it is a leap year; 2) for other years, if the year is evenly divisible by 100, then it is a regular year; 3) for other years, if the year is evenly divisible by 4, then it is a leap year; 4) all remaining years are not leap years. Thus, the years 1700, 1800, and 1900 are not leap years, since they are multiples of 100 but not 400. The years 1600 and 2000 are leap years, since they are multiples of 100 and multiples of 400. The years 2100, 2200 and 2300 are not leap years.

1st Jul 2020, 4:42 PM
stephen haokip
stephen haokip - avatar
2 Answers
+ 1
Thank you Martin Taylor Swift
1st Jul 2020, 4:54 PM
stephen haokip
stephen haokip - avatar
0
if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) { System.out.println("Leap year"); } else { System.out.println("Not a leap year"); } I hope this will help you....!!!
3rd Jul 2020, 9:09 AM
Arya Deep Chowdhury
Arya Deep Chowdhury - avatar