java,打印出100到500内所有的闰年,每行最多输出不超过四位
时间: 2024-09-13 07:17:52 浏览: 41
```java
public class LeapYearPrinter {
public static void main(String[] args) {
int count = 0;
for (int year = 100; year <= 500; year++) {
if (isLeapYear(year)) {
System.out.print(year + " ");
count++;
if (count % 4 == 0) {
System.out.println();
}
}
}
}
private static boolean isLeapYear(int year) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
}
```
阅读全文