//输入一个年份,判断该年是闰年还是平年
public static void test2() {
System.out.println("请输入年份");
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
if ((x % 400 == 0) || (x % 4 == 0 && x % 100 != 0)) {
System.out.println("该年是闰年");
} else {
System.out.println("该年不是闰年");
}
}
javaSE基础例题-输入年份后判断是闰年还是平年
于 2023-09-19 17:23:13 首次发布