new一个数组引起的问题

来源:互联网 发布:网络收音下载 编辑:程序博客网 时间:2024/06/07 08:03
package test;//文件名 : ExcepTest.javaimport java.io.*; class ExcepTest{public static void main(String args[]){   try{      int a[] = new int[3];      System.out.println("Access element three :" + a[3]);   }catch(ArrayIndexOutOfBoundsException e){      System.out.println("Exception thrown  :" + e);   }   System.out.println("Out of the block");}}

输出结果是:

Exception thrown  java.lang.ArrayIndexOutOfBoundsException: 3Out of the block

int a[] =new int[3];
表示数组a中只包含3个元素分别是a[0],a[1],a[2]

原创粉丝点击