我不确定如何获得所有内容的最大平均值、最小平均值和平均值。我已经在我的代码中为变量设置了值,但是我不确定如何在我的代码中输入平均值。任何帮助都会很棒!谢谢。导入 java.util.Scanner;
public class Averages {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int max = 0;
int min = 9000;
int score = 0;
int n;
int c;
int rowMaxNumber = 0;
int rowMinNumber = 0;
int columnMax = 0;
int columnMin = 0;
int averageMin = 0;
int averageMax = 0;
double average = 0;
System.out.println("How many rows?");
n = scan.nextInt();
for (int row = 1; row <= n; row++) {
System.out.println("How many student in row " + row + "?");
c = scan.nextInt();
for (int column = 1; column <= c; column++) {
System.out.println("Score for student " + column + " in row "
+ row + "?");
score = scan.nextInt();
rowMaxNumber = row;
columnMax = column;
rowMinNumber = row;
columnMin = column;
}
if (score >= max) {
max = score;
}
if (score < min) {
min = score;
}
}
System.out.println("Student " + columnMax + " of row " + rowMaxNumber
+ " was highest with " + max);
System.out.println("Student " + columnMin + " of row " + rowMinNumber
+ " was lowest with " + min);
System.out.println("Row " + rowMaxNumber + " had highest average with "
+ averageMax);
System.out.println("Row " + rowMinNumber + " had lowest average with "
+ averageMax);
System.out.println("Class average is " + average);
}
}