IF the year MOD 400 equals 0
THEN its a leap year
OR IF the year MOD 4 equals 0
AND the year MOD 100 does not equal 0
THEN its a leap year
The code to implement the above goes something like this:
public static boolean isLeapYear(int year) {
boolean leapYear = false;
if (((year % 400) == 0) || (((year % 4) == 0) && ((year % 100) != 0))) {
leapYear = true;
}
return leapYear;
}
No comments:
Post a comment