有下面程序段: Public class ArrayTest { Public static void main(String args[]) { int[] intArray=new int[3

admin2010-02-22  34

问题 有下面程序段:     Public class ArrayTest    {       Public static void main(String args[])       {           int[]  intArray=new int[3];           for(int I=0;I<3;I++)              {                   intArray[I]=I+2;                   System.out.println("IntArray["+I+"]"-"+intArray[I]);              }           System.out.println("------------");           Int arrLen=4;           IntArray=new int[arrLen];           For(int j=intArray.length;j>=0;j--}             {                      intArray [j]=j*3;                System.out.println("hello"+intArray[j]);            }       }    }    则运行的结果是(    )。

选项 A、编译出错
B、编译通过,但运行出错
C、可以运行,但有错误
D、以上都不对

答案2

解析 这是一道考查数组引用的题,目的是考查如何在程序中引用初始化后的数组。引用的方式为arrayName[index),其中index为数组的下标,可以为整数、变量和表达式,范围从0开始,一直到数组的长度减1。在Java语言中,是要对数组下标进行检查的。因此当程序运行到数组的长度值时,就发生了越界现象。
转载请注明原文地址:https://kaotiyun.com/show/469p777K
0

最新回复(0)