java定义方法判断闰年,在主函数里调用求1000~2000的闰年
来自 湖北省武汉市 的网友分享
(°C)
24682
```java
public class LeapYear {
public static void main(String[] args) {
for (int i = 1000; i <= 2000; i++) {
if (isLeapYear(i)) {
System.out.println(i + "是闰年");
}
}
}
public static boolean isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
return true;
} else {
return false;
}
}
}
```
public class LeapYear {
public static void main(String[] args) {
for (int i = 1000; i <= 2000; i++) {
if (isLeapYear(i)) {
System.out.println(i + "是闰年");
}
}
}
public static boolean isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
return true;
} else {
return false;
}
}
}
```