【发布时间】:2025-12-16 21:15:01
【问题描述】:
我正在尝试根据条件返回不同的数组值。这是我的代码,但它出错了。请帮我找出问题所在。
private static String subject[] = {"Mathematics", "English"};
private static String studentNum[] = {"1", "2"};
private static int marks[][] = {{56,51}, // Student 1 mark for Mathermatics
{69,85}}; // Student 2 mark for English
public static double AverageMarks(String aCode) {
double sum[] = new double[subject.length];
double average[] = new double[subject.length];
for(int j=0;j<subject.length;j++) {
for(int i=0;i<studentNum.length;i++) {
sum[j] += marks[j][i];
average[j] = (sum[j] / studentNum.length); // average[0] is the average mark of Mathermatics and average[1] is the average mark of English
}
if (aCode.equals(subject[j])) {
return average[j];
}
else {
return 0;
}
}
}
【问题讨论】:
-
您需要告诉我们有关错误的更多详细信息