【发布时间】:2015-11-12 18:21:23
【问题描述】:
for (int i = 0; i < 15; i+=3) {
System.out.print("Enter Exam Mark:");
Marks[i] = input.nextInt();
System.out.print("Enter Coursework Mark:");
Marks[i+1] = input.nextInt();
System.out.print("Enter Weighting:");
Marks[i+2] = input.nextInt();
}
public double[] computemarks(int[] Marks) {
double[] marks = new double[6];
double computedmark;
for (int x = 0; x < 15; x+=3) {
if (Marks[x] >= 35 && Marks[x+1] >= 35) {
computedmark = ((Marks[x+1] * Marks[x+2]) + (Marks[x] * (100.0 - Marks[x+2]))) / 100.0;
} else {
computedmark = Math.min(Marks[x], Marks[x+1]);
}
marks[x] = computedmark;
}
return marks;
}
为什么在运行时显示“ArrayIndexOutOfBoundsException”? 我已经玩过 for 循环,但它仍然无法正常工作。
仅供参考,Marks 数组在内存中有 18 个可用插槽。
【问题讨论】:
标签: java arrays compiler-errors