问题
单项选择题
下列程序的输出结果是( )。
Public class Test
Public static void main(String[]args)
int[]array=(2,4,6,8,10);
int size=6;
int result=-1;
try
for(int i=0;i<size&& result==-1;)
if(array[i]==20)result=i;
catch(ArithmeticException e)
System.out.println("Catch---1’);
catch(ArrayIndexOutOfBoundsException 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
解析: 本题考查了数组及for循环。本题数组定义的值为5,下标从0~4。数组越界,所以答案为B。