
结果:
ArrayIndexOutOfBoundsException/内层try-catch
发生ArithmeticException

结果:
ArrayIndexOutOfBoundsException/外层try-catch

不一定,程序可能会在finally语句前结束。

源代码:
import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int score;
int receiveScore;
System.out.println("输入一个整数:");
if(input.hasNextInt())
{
receiveScore=input.nextInt();
if(receiveScore<=100)
{
score=receiveScore;
}
else
{
System.out.println("错误:输入分数大于100");
score=101;
}
}
else
{
System.out.println("错误:输入的是非整数");
score=101;
}
if(score<=59)
{
System.out.println("不及格");
}
else if(score<=69)
{
System.out.println("及格");
}
else if(score<=79)
{
System.out.println("中");
}
else if(score<=89)
{
System.out.println("良");
}
else if(score<=100)
{
System.out.println("优");
}
}
}
运行结果:

