当我上这门课时,我没有得到总和/平均值。我收到下面列出的错误。我不确定我为什么会得到它。我是一个非常新的学生。
public class DebugEight2
{
public static void main(String[] args)
{
int[] someNums = {4,17,22,8,35};
int tot;
int x;
int sum = 0;
for(x = 0; x <= someNums.length; ++x)
tot = someNums[x];
sum = sum + someNums[x];
System.out.println("Sum is " + sum);
System.out.println("Average is " + sum * 1.0 / someNums.length);
}
}
错误:
"Exception in thread "main" java.lang.ArrayIndexOutofBoundsException: 4 at DebugEight1.main (DebugEight1.java:17)"