Q. Input a year in the method call box as argument and get the result from method return dialog box. true means the entered year is a leapyear, otherwise not.
Ans.
public class LeapYear
{
public boolean isLeapYear(int year)
{
if (year < 0) {
return false;
}
if (year % 400 == 0) {
return true;
} else if (year % 100 == 0) {
return false;
} else if (year % 4 == 0) {
return true;
} else {
return false;
}
}
}
Discussing Java application programming across the barrier of classroom for the young minds.
Wednesday, March 17, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment