编程没有报错求平均值跟求数组的最大值

img

img


编程没有报错求平均值跟求数组的最大值
一直是
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 5
at Exmaple6_2.sort(Exmaple6_2.java:24)
at Exmaple6_2.main(Exmaple6_2.java:15)

13行以下的删除。用以下示例代码:

        int[] scores = {12,3,34,67,100,99};
        IntStream intStream = IntStream.of(scores);
        IntSummaryStatistics statistics = intStream.summaryStatistics();
        System.out.println("the max:" + statistics.getMax());
        System.out.println("the average:" + statistics.getAverage());

可参考我的文章

for循环里a[0] > a[-1]越界了

你的报错,第24行,j初始值是0,判度的时候,数组越界