Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 数组越界

Posted yanjiemao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 数组越界相关的知识,希望对你有一定的参考价值。

程序出现了以下报错是什么原因呢?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at case50.Case07.main(Case07.java:25)
是数组越界了

for (int i = 0; i <= ch.length; i++) {   //数组角标从零开始,在这里应为 i < ch.length
            if (ch[i] >= '0' && ch[i] <= '9') {
                digital++;
            } else if ((ch[i] >= 'a' && ch[i] <= 'z') || (ch[i] >= 'A' && ch[i] <= 'Z')) {
                character++;
            } else if (ch[i] == ' ') {
                blank++;
            } else {
                other++;
            }
        }

技术图片

以上是关于Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 数组越界的主要内容,如果未能解决你的问题,请参考以下文章

Exception in thread "main" java.lang.UnsupportedClassVersionError

Exception in thread "main" java.util.InputMismatchException

Exception in thread "main" java.lang.ClassCastException

Exception in thread "main" java.lang.UnsatisfiedLinkError:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1

Exception in thread "main" java.lang.NullPointerException