輸入一個星期數,如何編寫不管輸入的是大寫漢字還是阿拉伯數字都可以識別的程序
?System.out.println("請輸入一個星期數");
???Scanner?in=new?Scanner(System?in);
???int?x=in.nextInt();
???if(xxxxx)?System.out.println("請輸入一個星期數");
???Scanner?in=new?Scanner(System?in);
???int?x=in.nextInt();
???if(xxxxx)2016-09-04
舉報
2016-09-04
好像沒有一個數據類型可以支持匹配數字類型的和漢子類型的。
2016-09-06
do{
????System.out.println("輸入錯誤請重新輸入");
????????System.out.println("請輸入一個星期數");
???????? Scanner in=new Scanner(System.in);
?? ????int x=in.nextInt();
??
}while(x<1 || x>7)
//只要輸入數字小于1或者大于7就循環輸入
2016-09-04
?System.out.println("請輸入一個星期數");
???????? Scanner in=new Scanner(System.in);
?? int x=in.nextInt();
??? if((x<1||x>7)){
???? System.out.println("輸入錯誤請重新輸入");