题目描述: 编写程序,显示从101到2100期间所有的闰年,每行显示10个。数字之间用一个空格字符隔开,同时显示这期间闰年的数目。
public class P5_27 {
public static main void (String[] args) {
int count = 0; //计数器,后面换行使用
int num = 0; //记录闰年总数
//接下来判断闰年
for (int year = 101; year <= 2100; year++) {
if (year % 4 == 0 && year % 100 != 0) ||
(year % 400 == 0)) {
System.out.print(year + " ");
count++;
num++;
//接下来处理格式问题,如果count % 10为0那么就要换行
if (count % 10 == 0) {
System.out.println();
}
}
}
//最后记录101到2100闰年的总数目
System.out.println("leapyear's numbers are: " + num);
}
}