The cool logic to decide whether the given year is a leap year or not .. !!
/**
* Checks if the given year is a leap year.
*
* @param year
* the year
* @return true, if is leap year
*/
public boolean isLeapYear(final int year)
{
boolean isLeapYear = true; // Optimist
final int divideByFour = year % 4;
final int divideBy100 = year % 100;
final int divideBy400 = year % 400;
if (divideBy400 == 0)
{
isLeapYear = true;
}
else if (divideBy100 == 0)
{
isLeapYear = false;
}
else if (divideByFour == 0)
{
isLeapYear = true;
}
else
{
isLeapYear = false;
}
return isLeapYear;
}
/**
* Checks if the given year is a leap year.
*
* @param year
* the year
* @return true, if is leap year
*/
public boolean isLeapYear(final int year)
{
boolean isLeapYear = true; // Optimist
final int divideByFour = year % 4;
final int divideBy100 = year % 100;
final int divideBy400 = year % 400;
if (divideBy400 == 0)
{
isLeapYear = true;
}
else if (divideBy100 == 0)
{
isLeapYear = false;
}
else if (divideByFour == 0)
{
isLeapYear = true;
}
else
{
isLeapYear = false;
}
return isLeapYear;
}
No comments:
Post a Comment