根据输入的年份判断是否为闰年,如果为世纪闰年输出“Century l eap year.”,如果为普通闰年输出“leap year.”,如果不为闰年输出“It i s not leap year.”。并设计测试数据进行判定覆盖测试。
时间: 2024-05-14 17:12:32 浏览: 99
代码实现:
```python
year = int(input("请输入年份:"))
if year % 400 == 0:
print("Century leap year.")
elif year % 100 == 0:
print("It is not leap year.")
elif year % 4 == 0:
print("leap year.")
else:
print("It is not leap year.")
```
测试数据设计:
1. 输入2000,期望输出“Century leap year.”
2. 输入1900,期望输出“It is not leap year.”
3. 输入2020,期望输出“leap year.”
4. 输入2022,期望输出“It is not leap year.”
5. 输入1600,期望输出“Century leap year.”
相关问题
根据输入的年份判断是否为闰年,如果为世纪闰年输出“Century leap year.”如果为普通闰年输出“leap year.”如果不为闰年输出“It is not leap year.”并设计测试数据进行覆盖测试,使用Visio绘制程序框图。
判断闰年的方法如下:
1. 能被4整除但不能被100整除的年份是普通闰年。
2. 能被400整除的是世纪闰年。
下面是代码实现:
```
year = int(input("请输入一个年份:"))
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print("Century leap year.")
else:
print("It is not leap year.")
else:
print("leap year.")
else:
print("It is not leap year.")
```
测试数据:
| 输入 | 输出 |
| ---- | ---- |
| 2000 | Century leap year. |
| 2020 | leap year. |
| 1900 | It is not leap year. |
| 2001 | It is not leap year. |
Visio绘制的程序框图如下:
![程序框图](https://img-blog.csdnimg.cn/20210915104152396.png)
写一段Java代码 根据输入的年份判断是否为闰年,如果为世纪闰年输出“Century l eap year.”,如果为普通闰年输出“闰年”。,如果不为闰年输出“It i s not leap year.”。并设计测试数据进行判定覆盖测试。
```
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int year = scanner.nextInt();
if (year % 400 == 0) {
System.out.println("Century leap year.");
} else if (year % 4 == 0 && year % 100 != 0) {
System.out.println("Leap year.");
} else {
System.out.println("It is not leap year.");
}
}
}
```
测试数据:
输入:2000,预期输出:Century leap year.
输入:2004,预期输出:Leap year.
输入:1900,预期输出:It is not leap year.
输入:2021,预期输出:It is not leap year.
阅读全文