I'm creating a calculator that tells you if a year would be considered a leap year or not. I keep hitting a snag, when the year entered is 1924 the result = "is Not a Leap Year" when it should = "is a Leap Year". I've re-written this 3 different ways but am unable to resolve this portion, some fresh eyes would be appreciated.
LeapYearCalculator
class:
public class LeapYearCalculator {
public static boolean isLeapYear (int year) {
if ((year<=0) || (year>=1000)) {
System.out.println(year+" is NOT a Leap Year");
}
if (year % 4 == 0) {
if (year % 100== 0) {
return (year % 400 == 0);
}
System.out.println(year+" is NOT a Leap Year");
return true;
}
System.out.println(year+" is NOT a Leap Year");
return false;
}
}
Main
class:
public class Main {
public static void main(String[] args) {
LeapYearCalculator.isLeapYear(1924);
}
}
Aucun commentaire:
Enregistrer un commentaire