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); } }
添加回答
舉報
0/150
提交
取消