ArrayIndexOutOfBoundsException

dos窗口编译java文件:javac xxx.java

dos窗口运行class文件:java xxx

/** 
* @author liangyadong 
* @date 2016年9月27日 下午9:34:51 
* @version 1.0 
* 
* 演示ArrayIndexOutOfBoundsException
* 
* 编译时并不出错,运行时才会报数组角标越界异常!
*/
public class Array {
    
    public static void main(String[] args) {
        
        int arr[] = new int[3];
        arr[0] = 1;
        arr[1] = 2;
        arr[2] = 3;
        arr[3] = 4;// ArrayIndexOutOfBoundsException
        
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
        
    }
}

 

posted @ 2016-09-27 22:41  习惯沉淀  阅读(1125)  评论(0编辑  收藏  举报