写一段Java代码 根据输入的年份判断是否为闰年,如果为世纪闰年输出“Century l eap year.”,如果为普通闰年输出“闰年”。,如果不为闰年输出“It i s not leap year.”。并设计测试数据进行判定覆盖测试。
时间: 2024-03-28 11:11:48 浏览: 82
Java开发自学100天,Java开发必背代码 判断年份是否为闰年
```
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.
阅读全文