lundi 16 mars 2020

Why does this if statement return the value true?

public static boolean isLeapYear(int year) {
    if(year < 1 || year > 9999) {
        return false;
    }else {
        if(year % 4 == 0) {
            return true;
        }if(year % 100 != 0 && year % 400 == 0) {
            return true;
        }else {
            return false;
        }
    }
}

The integer (year) is 9000, it should have returned false but got true instead. What went wrong?

Aucun commentaire:

Enregistrer un commentaire