Java对于Scanner输入数据格式不正确的异常处理


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删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM