题目:
如果某年可以被4整除而不能被100整除,或者可以被400整除,那么这一年就是闰年。
代码实现:
public class LeapYear {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入年份:");
int year = input.nextInt();
boolean isLeapYear = (year% 4 == 0 && year % 100 != 0 || year % 400 ==0);
System.out.println( year+"是闰年吗?" + isLeapYear);
}
}
本文提供了一个简单的Java程序来判断一个年份是否为闰年。通过该程序,用户输入一个年份,程序将根据闰年的规则(能被4整除且不能被100整除,或者能被400整除)输出判断结果。

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



