Java Utililty Methods Leap Year Check

List of utility methods to do Leap Year Check

Description

The list of methods to do Leap Year Check are organized into topic(s).

Method

booleanisLeapYear(int y)
is Leap Year
if (y % 4 == 0) {
    if (y % 100 == 0) {
        if (y % 400 == 0) {
            return true;
        } else {
            return false;
    } else {
...
booleanisLeapYear(int y)
Check if the given year is leap year.
boolean result = false;
if (((y % 4) == 0) && 
        ((y < 1582) || 
                ((y % 100) != 0) || 
                ((y % 400) == 0))) { 
    result = true; 
return result;
...
booleanisLeapYear(int year)
is Leap Year
int mod4;
int mod400;
boolean leap_year;
mod4 = year % 4;
mod400 = year % 400;
if (mod4 == 0 && mod400 != 100 && mod400 != 200 && mod400 != 300) {
    leap_year = true;
} else {
...
booleanisLeapYear(int year)
is Leap Year
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
booleanisLeapYear(int year)

Verify if a given year is leap.

if (year % 4 == 0) {
    return year % 100 != 0 ? true : year % 400 == 0;
return false;
booleanisLeapYear(int year)
is Leap Year
Calendar calendar = Calendar.getInstance();
calendar.set(year, 2, 1);
calendar.add(Calendar.DATE, -1);
if (calendar.get(Calendar.DAY_OF_MONTH) == 29) {
    System.out.println(year + " year is a leap year.");
    return true;
} else {
    System.out.println(year + " year is not a leap year.");
...
booleanisLeapYear(int year)
Determines whether or not a year is a leap year.
if ((year & 3) != 0) {
    return false;
if ((year % 100) != 0) {
    return true;
return (year % 400) == 0;
booleanisLeapYear(int year)
is Leap Year
return year >= gregoranCutoverYear ? ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)))
        : (year % 4 == 0);
booleanisLeapYear(int year)
Leap years occur in years exactly divisible by four, except those years ending in 00 are leap years only if they are divisible by 400.
boolean isLeapYear = false;
if (year > 0 && (year % 4) == 0) {
    isLeapYear = true;
    if ((year % 1000) == 0) 
        if ((year % 400) != 0) {
            isLeapYear = false;
return (isLeapYear);
booleanisLeapYear(int year)
Cheks is leap year or not
if (year < 1582) {
    if (year % 4 == 0)
        return true;
if (year % 100 == 0 && (year / 100) % 4 != 0)
    return false;
if (year % 4 == 0)
    return true;
...