public class ArryDemo05 {
public static void main(String [] args)
{
//声明一个数组
int arr [] = {78,88,94,96,35,28};
//声明最大值与最小值的初始化为零
int max = 0, min = 0;
//假定最大值与最小值都是第一个元素
max = min = arr[0];
for (int i = 0;i <=arr.length;i ++)
{
if (arr[i]< min)
{
min = arr[i];
}
if (arr[i] > max )
{
max = arr[i];
}
}
System.out.println("最小值为:"+min);
System.out.println("最大值为:"+max);
}
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
at ArryDemo05.main(ArryDemo05.java:17)
看不出来索引怎么超出异常了,求大神指导。
|