下列程序的输出结果是( )。 Public class Test { Public static void mai n(Stri ng[]args){ i nt []array =(2,4,6,8,10); i nt size =6; i

admin2012-12-02  57

问题 下列程序的输出结果是(  )。
Public class Test {
Public static void mai n(Stri ng[]args){
  i nt []array =(2,4,6,8,10);
  i nt size =6;
  i nt result =-1;
  try {
   for (i nt i =0;i <size &&result ==-1;)
if (array[i]==20)result =i ;
  }
  catch(ArithmeticException e){   
Syste m.out .pri ntln("Catch ---1");
  }
  catch(ArrayIndexOut OfBounds Exception e){
   Syste m.out .pri ntln("Catch ---2");
  }
  catch(Exception e){
   Syste m.out .pri ntln("Catch ---3"); }

选项 A、Catch ---1
B、Catch ---2
C、Catch ---3
D、以上都不对

答案B

解析 本题考查了数组及for 循环。本题数组定义的值为5,下标从0~4。数组越界,所以答案为B。
转载请注明原文地址:https://kaotiyun.com/show/G9ID777K
0

最新回复(0)