题目
题目概述
5.27(显示闰年)编写程序,显示从101到2100期间所有闰年,每行显示10个。数字之间用一个空格字符隔开,同时显示这期间闰年的数目
破题
- 通过for循环遍历
- 打标判断是否是闰年,设置技术对象以判断是否需要换行
代码
public class Test5_27 {
public static void main(String[] args) {
boolean bool = false;
int count = 0;
for (int year = 101; year <= 2100; year++) {
bool = false;
if (((year % 4 == 0) && (year % 100 != 0)) || ((year % 400 == 0) && (year % 100 == 0))){
bool = true;
count++;
System.out.print(year + " ");
if (count % 10 == 0) {
System.out.println();
}
}
}
System.out