/输出 1000 - 2000 之间所有的闰年
//公历闰年判定遵循的规律为:四年一闰、百年不闰、400年再闰
//1.普通闰年:闰年能被4整除且不能100整除(即i%4==0 && i%100!=0)
//2.世纪闰年:每400年一闰(i%400 ==0)
public static void main(String[] args) {
int count = 0;
int number = 0;
for (int i = 1000; i <= 2000; i++) {
if (i % 4 == 0 && i % 100!= 0) {
System.out.print(i + " ");
count++;
number++;
}
if (i % 400 == 0) {
System.out.print(i + " ");
count++;
number++;
}
if (count == 15) {
System.out.println();
count = 0;
}
}
System.out.println();
System.out.println("一共有:" + number + "个闰年");
}
}
输出闰年:输出 1000 - 2000 之间所有的闰年
最新推荐文章于 2024-05-16 10:23:10 发布