int[] eggs={1,2,3,4,5};
int[] ham=new int[]{77,96};
ham=eggs;
ham[3]=0;
for(int i:ham){
System.out.println(ham[i]);
}
上面这段程序运行后输出如下:
2
3
0
1
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at doItMyself.TestArray.main(TestArray.java:73)
哪位高手能给解释一下么?
------解决方案--------------------
- Java code
for(int i : ham){ System.out.println(ham[i]); }