Exception in thread “main“ java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for lengt

项目场景:

IntelliJ IDEA


问题描述:

控制台报错:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5 at HelloWorld.main(HelloWorld.java:14)

Exception in thread “main“ java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for lengt


原因分析:

数组下标溢出

Exception in thread “main“ java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for lengt


解决方案:

将下标改为数组定义的个数之内

Exception in thread “main“ java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for lengt

Exception in thread “main“ java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for lengt