0
이전 메소드는 사용자 입력에 의해 정의 된 크기로 2D 이중 배열을 구성하고 채 웁니다. computeCategoryAverages는 가운데 색인을 가져 와서 평균 한 다음 최종 색인에 넣습니다. computeOverallAverage는 0 색인 (가중치)에 최종 색인 을 곱하고 그 수를 저장 한 다음 매회 추가 할 때까지 반복합니다 .2D 배열의 열을 어떻게 곱하면됩니까? Java
Weight Grade1 Grade2 Grade3 Average
----------------------------------------
1| 3.0 456.0 4356.0 456.0 1756.0
2| 4.0 3456.0 674.0 34534.0 12888.0
3| 2.0 236.0 791.0 536.0 521.0
Example of what computeOverallAverage is supposed to do:
3.0 * 1756.0 = 5268
4 * 12888.0 = 51552
5268 + 51552= 56820
2 * 521= 1042
56820 + 1042 = 57862
computeCategoryAverages는 완벽하게 작동합니다.
public static double[][] computeCategoryAverages(double[][] scoreArray){
for(int i = 0; i < scoreArray.length; i++){
double sum = 0;
int numOfAssign = 0;
double average=0.0;
System.out.printf("The Average for category:%d:",i+1);
System.out.println();
for(int j = 1; j < scoreArray[i].length-1; j++){
numOfAssign++;
sum = sum + scoreArray[i][j];
}
average = sum/numOfAssign;
scoreArray[i][scoreArray[i].length-1] = average;
}
return scoreArray;
}
의 I는 데 발행 computeOverallAverage 함께, 내가 열을 곱 additiion로를 복잡하게하는 루프가 기능이 제대로 배열을 만드는 방법을 정말 모르겠어요. 에서
// Compute the overall average
public static double computeOverallAverage(double[][] scoreArray){
double currentAverage = 0;
for(int i = 0; i < scoreArray[i].length-1; i++){
//(weightedAverage = average *weight);
double wAverage = scoreArray[i][scoreArray[i].length-1] * scoreArray[i][0];
currentAverage += wAverage;
}
return currentAverage;
}
computeoverallaverage의 출력은 무엇입니까? –
computeOverallAverage의 출력은 각 행의 가중치 열 배 평균 열의 합인 double이어야합니다. 예를 들어 표 아래의 계산을보십시오. – Evan