关于异常处理的问题,我处理异常之后,它不继续往下运行了

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)


一起创业
浏览 2386回答 2
2回答

qq___571

用finally
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
Android