1、手写JAVA代码实现:输入一个年份判断平闰年,提示:年份能被4整除且不能被100整除的为闰年,或者年份能被400整除的是闰年;否则为平年。
时间: 2023-10-23 17:14:15 浏览: 42
好的,以下是实现代码:
```java
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入年份:");
int year = scanner.nextInt();
boolean isLeapYear = false;
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
isLeapYear = true;
}
if (isLeapYear) {
System.out.println(year + "年是闰年!");
} else {
System.out.println(year + "年是平年!");
}
}
}
```
我们使用 Scanner 类从控制台读取用户输入的年份,然后使用 if 语句判断该年份是否为闰年,最后输出结果。
相关问题
手写代码实现:输入一个年份判断平闰年,提示:年份能被4整除且不能被100整除的为闰年,或者年份能被400整除的是闰年;否则为平年。
好的,这是一个简单的判断平闰年的问题。以下是手写代码实现:
```
year = int(input("请输入一个年份:"))
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
print(year, "年是闰年")
else:
print(year, "年是平年")
```
希望能对你有所帮助!
使用python输入一个年份判断闰年能被4整除但不能被100整除,或者能被400整除年份都是闰年
好的,以下是Python代码实现:
```python
year = int(input("请输入年份:"))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(year, "年是闰年")
else:
print(year, "年不是闰年")
```
代码中,首先使用 `input()` 函数获取用户输入的年份,然后使用 `if` 语句判断该年份是否为闰年,根据题目要求,判断条件为:能被4整除但不能被100整除,或者能被400整除。如果满足条件,则输出该年份是闰年,否则输出该年份不是闰年。