Exception in thread “main“ java.lang.ArrayIndexOutOfBoundsException
阿新 • • 發佈:2021-02-06
技術標籤:java
陣列下標越界異常
**
**
程式碼演示
package array;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
public class Demo01 {
public static void main(String[] args) {
int[] number; //宣告陣列
// int nums2[]; //知道就行
number = new int[10]; //建立陣列
//給陣列元素賦值
number[ 0] = 1;
number[1] = 2;
number[2] = 3;
number[3] = 4;
number[4] = 5;
number[5] = 6;
number[6] = 7;
number[7] = 8;
number[8] = 9;
number[9] = 10;
System.out.println((number[9])); //正常取出
System.out.println("---------------" );
System.out.println((number[10])); //不存在陣列下標為10的,越界異常
}
}