语法没有错误,是逻辑错误吗?
package ShuzuDemo;public class Shuzu {
public static void main(String[] args){
int[]a={2,3,4,5,9,7,8};
int max=0;
for(int i=1;i<a.length;i++){
if (a[i]>a[i+1]&&a[i]>max){
max=a[i];
}
else if(a[i+1]>a[i]&&a[i+1]>max){
max=a[i+1];
}
}
System.out.println(max);
}
}
报错:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at ShuzuDemo.Shuzu.main(Shuzu.java:8)
语法没有错误,是逻辑错误吗?新人不懂,请大神帮助!