Scanner in = new Scanner(System.in);
int sum;
int count = 0;
System.out.println("输入10个整数");
for (int i = 0; i < 10; i++) {
try {
sum = in.nextInt();//输入w,抛出InputMismatchException,异常我处理了
} catch (InputMismatchException e) {
System.out.println("请输入整数");
sum = in.nextInt(); //在这里我什么没输入,直接给我报异常,这个是17行;新手,请多多帮忙
//现在挺困扰的;
}
console:
输入10个整数
w
请输入整数
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at com.imooc.PrintBig.main(PrintBig.java:17)
qq___571