1、定义一个方法getLeap传入年份year判断传入的年份是否闰年返回true是闰年false不是闰年。写一个测试类测试下2016年是否闰年。 提示:能被4整除且不能被100整除的为闰年或者能被400整除的是闰年。返回类型:boolean参数列表:int year
public class LeapYear { public static boolean getLeap(int year) { if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) { return true; } else { return false; } }
public static void main(String[] args) {
int year = 2016;
boolean isLeapYear = getLeap(year);
System.out.println(year + "年是否闰年:" + isLeapYear);
}
}
原文地址: https://www.cveoy.top/t/topic/hXTp 著作权归作者所有。请勿转载和采集!