int year=0,month=0,day=0,sum=0;
do{
System.out.println("请输入年");
if(input.hasNext()){
year=input.nextInt();
if(year>=1900){
}else{
System.out.println("错误!输入的年份不能小于1900年;\n请重新输入");
}while(true);
}
System.out.println("请输入月");
if(input.hasNext()){
month=input.nextInt();
if(month<=12||month>=1){
}else{
System.out.println("错误!你输入的月份有误;");
while(true);
}
}
System.out.println("请输入日");
if(input.hasNext()){
day=input.nextInt();
if(day<=31&day>=1){
if(day<=31&&month==1||month==3||month==5||month==7||month==8||month==10||month==12){
}else if(day<=30&&month==4||month==6||month==9||month==11){
}else if(month==2&&day<=29&&(year%4==0&&year%100!=0||year%400==0)){
}else if(month==2&&day<=28){
}else{
System.out.println("错误!"+year+"年的"+month+"月没有"+day+"天");
while(true);
}
}else{
System.out.println("错误!"+year+"年的"+month+"月没有"+day+"天");
while(true);
}
}
}while(true);
}
}
相关分类