下列程序的输出结果是( )。 public class ArrayTest { public static void mai n(Stri ng args[]) { i nt[]i nt Array =ne wi nt[3] for(i nt

admin2012-12-02  20

问题 下列程序的输出结果是(  )。
public class ArrayTest

public static void mai n(Stri ng args[])

  i nt[]i nt Array =ne wi nt[3]
  for(i nt i =0;i <3;i ++)
   {
i nt Array[i]=i +2;
    syste m.out .pri ntln("Int Array["+i +"]"=i nt Array[i]);
   }
  Syste m.out .pri ntln("----------");
  i nt arrLen =4;
  Int Array =ne wi nt[arrLen];
  For(i nt j=i nt Array .length ;j>=0;j--)
  {
   i nt Array[j]=j*3;
   syste m.out .pri ntln("hello"+i nt Array[j]);
  }


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

答案B

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

最新回复(0)