
* 经查阅资料:年分为闰年和平年。
* 闰年的判断方法:
* 公历年份是4的倍数,且不是100的倍数,为普通闰年。
* 公历年份是整百数,且必须是400的倍数才是世纪闰年
* 考虑升级:
* 判断闰年且判断是普通闰年还是世纪闰年。
* 若不是闰年,提示为平年。
* 最终功能:
* 获取用户输入年份判断是普通闰年、世纪闰年还是平年。
* 每次查询完成后询问用户是否继续查询,按1继续查询,按任意键推出查询。
package cn.itcast_Java100;
import java.util.Scanner;
public class Java1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Scanner sc2 = new Scanner(System.in);
while (true) {
System.out.println("请输入一个年份。");
int x = sc.nextInt();
if (x % 4 == 0) {
if (x % 100 == 0) {
System.out.println(x + "年是世纪闰年。");
} else {
System.out.println(x + "年是普通闰年。");
}
} else {
System.out.println(x + "年是平年。");
}
System.out.println("按1继续查询,按任意键退出查询。");
int y = sc2.nextInt();
if (y != 1) {
System.out.println("感谢您的使用,已退出本次查询。");
break;
}
}
}
}