这是我的要求。确定年份是否为闰年算法:
- 如果年份可以被4整除,则为闰年
- 除非年份可以被100整除,否则就不是闰年
- 除非年份可以被400整除,否则就是闰年
- 否则不是闰年
我需要知道我做对了吗?
private static boolean isLeapYear(int userInput){
boolean leapYear= false;
if (userInput % 4 == 0 ){
leapYear = true;
if (userInput % 4 == 0 && userInput % 100 ==0) {
leapYear = false;
if(userInput % 400 == 0){
leapYear = true;
}
}
}
else {
leapYear = false;
}
return leapYear;
}