package base;
/*
* 类名 LeapYear.java
* 说明 判断闰年
* 创建日期 2011-3-9
* 作者 kobe
* 版权 ***
*/
public class LeapYear {
public static void main(String[] args) {
int year = 1804;
System.out.print(isLeapYear(year) ? year + " is leap year" : year + " is not leap year");
}
/**
* 判断年份是否为闰年
* 判断闰年的条件, 能被4整除同时不能被100整除,或者能被400整除
*/
public static boolean isLeapYear(int year) {
boolean isLeapYear = false;
if (year % 4 == 0 && year % 100 != 0) {
isLeapYear = true;
} else if (year % 400 == 0) {
isLeapYear = true;
}
return isLeapYear;
}
}
判断闰年的JAVA实现方式
最新推荐文章于 2025-09-28 19:07:20 发布
本文提供了一个简单的Java程序,用于判断指定年份是否为闰年。程序定义了isLeapYear方法,通过检查年份能否被4整除且不能被100整除,或者能被400整除来判断是否为闰年。
487

被折叠的 条评论
为什么被折叠?



