根据输入的年份判断是否为闰年,如果为世纪闰年输出“Century leap year.”如果为普通闰年输出“leap year.”如果不为闰年输出“It is not leap year.”并设计测试数据进行覆盖测试,使用Visio绘制程序框图。
时间: 2024-06-19 07:02:40 浏览: 117
判断闰年的方法如下:
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)
相关问题
根据输入的年份判断是否为闰年,如果为世纪闰年输出“Century l eap year.”,如果为普通闰年输出“leap year.”,如果不为闰年输出“It i s not leap year.”。并设计测试数据进行判定覆盖测试
测试用例设计:
输入:2000
输出:Century leap year.
输入:2004
输出:leap year.
输入:1900
输出:It is not leap year.
输入:2001
输出:It is not leap year.
输入:0
输出:It is not leap year.
输入:-2000
输出:It is not leap year.
输入:2100
输出:It is not leap year.
输入:2020
输出:leap year.
输入:2024
输出:leap year.
输入:2400
输出:Century leap year.
写一段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.
阅读全文
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)