62,614
社区成员
发帖
与我相关
我的任务
分享
while(month >12 ¦ ¦ month <1);
public static void main(String[] args) {
int month=0;
System.out.println("Input the month");
do{
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();//这里你要读整行!不是读一位!
try {
month = Integer.valueOf(s);
}catch(Exception e) {
System.out.println("输入错误!请重新输入!");
System.exit(1);
}
if(month < 1 ||month > 12)
System.out.println("Error,Input again");
}while(month > 12||month < 1);
switch (month){
case 1:System.out.println("31");break;
case 3:System.out.println("31");break;
case 5:System.out.println("31");break;
case 7:System.out.println("31");break;
case 8:System.out.println("31");break;
case 10:System.out.println("31");break;
case 12:System.out.println("31");break;
case 2:System.out.println("28");break;
case 4:System.out.println("30");break;
case 6:System.out.println("30");break;
case 9:System.out.println("30");break;
case 11:System.out.println("30");break;
}
}
while(month > 12 && month < 1);