Posted by: Slackdemic September 28, 2006
Login in to Rate this Post:
0
?
Didn't mean to be rude earlier, guys, but what I did is good:
Every year divisible by 4 is a leap year.
But every year divisible by 100 is NOT a leap year
Unless the year is also divisible by 400, then it is still a leap year.
The year that is divisible by 100 is not leap year UNLESS it is divisible by 400! See there? That's exactly what I did. See the if loop:
Posted on 09-28-06 6:38 PM Reply | Notify Admin
ny serious Java people in here? For some reasons, the following code doesn't work for leap year. Any help/suggestion is appreciated.
The classes are Date and TestDate:
public void addMonth(int m)
{
month = month + m;
if (month>12)
{
month-=12;
addYear(1);
}
}
public boolean isLeap(int y)
{
if (y%100==0)
{
if (y%400==0)
return true; -----------> means, if it is divisible by 100 AND 400, return true
else
return false; ------>if it is divisible ONLY by 100....return false..
}
else if (y%4==0)
return true;
return false;
}