第1个回答 2016-05-14
public class TestAverage {
private static int[][] studentGrade = new int[3][3];
private static double[] average = new double[3];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
TestAverage ta = new TestAverage();
int i = 0, j = 0;
while(sc.hasNext()) {
studentGrade[i][j] = sc.nextInt();
if(j == 2 && i == 2) {
break;
}
else if(j == 2) {
j = 0;
i++;
}else {
j++;
}
}
average[0] = ((studentGrade[0][0] + studentGrade[0][1] + studentGrade[0][2])/3);
average[1] = ((studentGrade[1][0] + studentGrade[1][1] + studentGrade[1][2])/3);
average[2] = ((studentGrade[2][0] + studentGrade[2][1] + studentGrade[2][2])/3);
System.out.println("第一个同学的平均成绩为:"+average[0]);
System.out.println("第二个同学的平均成绩为:"+average[1]);
System.out.println("第三个同学的平均成绩为:"+average[2]);
}
}
输入9个数字回车就行本回答被网友采纳