一般写法
public class TestDemo3 {
public static void main(String[] args) {
for (int year = 1000; year < 2000; year++) {
if(year % 100 != 0) {
if(year % 4 == 0) {
System.out.println(year+"是闰年");
}
}
else {
if(year % 400 == 0) {
System.out.println(year+"是闰年");
}
}
}
}
简化后
public class TestDemo3 {
public static void main(String[] args) {
for (int year = 1000; year < 2000; year++) {
if(year % 100 != 0 && year % 4 == 0 || year % 400 == 0) {
System.out.println(year+"是闰年");
}
}
}
本文提供了一种简洁高效的闰年判断算法实现,通过两种不同的Java代码示例展示了如何判断1000年至2000年间的闰年。该算法考虑了普通年份和世纪年份的闰年规则。
489

被折叠的 条评论
为什么被折叠?



