全部题库 / Java / 试题详情
单选题 Java
2013-07-30

下列程序的输出结果是(  )。
Public class Test{
Public static void main(String[]args){
int[]array=(2,4,6,8,10);
int size=6;
int result=-l:
try{
for(int i=0;i<size&&result= =-1:)
if(array[i]= =20)result=i:
}
catch(ArithmeticException e){
System.out.println("Catch---1");
}
catch(ArraylndexOutOfBoundsException e){
System.out.println("Catch---2"):
}
catch(Exception e){
System.out.println("Catch---3"):
}
}

A.Catch---1 
B.Catch---2
C.Catch---3
D.以上都不对

参考答案

B

答案解析

B。【解析】本题考查了数组及for循环。本题数组定义的值为5,下标从0~4。数组越界,所以答案为B。

你可能感兴趣的试题