1 Scanner scanner = new Scanner(System.in); 2 int score = 0; 3 while(!scanner.hasNextInt()) { 4 System.out.println("輸入的類型不正確,請重新輸入:"); 5 //作用是將上面輸入的那個值取出來,以便下次重新輸入值 6 String strscore = scanner.next(); 7 } 8 score = scanner.nextInt(); 9 return score;
1 Scanner scanner = new Scanner(System.in); 2 int score = 0; 3 while(!scanner.hasNextInt()) { 4 System.out.println("輸入的類型不正確,請重新輸入:"); 5 //作用是將上面輸入的那個值取出來,以便下次重新輸入值 6 String strscore = scanner.next(); 7 } 8 score = scanner.nextInt(); 9 return score;
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。