为了账号安全,请及时绑定邮箱和手机立即绑定

java二维数组的使用?

/ 猿问

java二维数组的使用?

申涂 2020-04-13 17:38:32

录入学生考试多门课程后的成绩。输入多门课程的名称,输入参加考试这门课程的人数,录入他们考试的成绩,然后按下面图中的样式输出。http://img1.sycdn.imooc.com/5e94330300011bc510220295.jpg

查看完整描述

1 回答

已采纳
?
KeepLearning_XU

package temptest;


import java.util.Scanner;


public class Test7 {


public static void main(String[] args) {


int peopleNumber;

Scanner sc = new Scanner(System.in);

System.out.println("请输入参加考试的人数:");

peopleNumber = sc.nextInt();

String[] peopleName = new String[peopleNumber];

System.out.println("请输入考生姓名:");

for (int i = 0; i < peopleName.length; i++) {

peopleName[i] = sc.next();

}

int courseNumber;

System.out.println("请输入考试门数:");

courseNumber = sc.nextInt();

String[] courseName = new String[courseNumber];

System.out.println("请输入考试课程名称:");

for (int i = 0; i < courseName.length; i++) {

courseName[i] = sc.next();

}

int[][] grade = new int[peopleNumber][courseNumber];

for (int i = 0; i < grade.length; i++) {

System.out.println("请输入考生" + peopleName[i] + "的考试成绩:");

for (int j = 0; j < grade[i].length; j++) {

System.out.println("请输入" + courseName[j] + "的考试成绩:");

grade[i][j] = sc.nextInt();

}

}

int[] gradeSum = new int[courseNumber];

for (int i = 0; i < gradeSum.length; i++) {

for (int j = 0; j < courseNumber; j++) {

gradeSum[i] += grade[i][j];

}

}

int[] gradeAve = new int[courseNumber];

for (int i = 0; i < gradeAve.length; i++) {

gradeAve[i] = gradeSum[i] / courseNumber;

}

System.out.println();

System.out.println("显示如下:");

System.out.print("学生:\t");

for (int i = 0; i < courseName.length; i++) {

System.out.print(courseName[i] + "\t\t");

}

System.out.println("总分:\t平均分");

for (int i = 0; i < peopleNumber; i++) {

System.out.print(peopleName[i] + "\t\t");

for (int j = 0; j < courseNumber; j++) {

System.out.print(grade[i][j] + "\t\t");


}

System.out.println(gradeSum[i] + "\t\t" + gradeAve[i]);


}


}


}


查看完整回答
反对 回复 2020-04-13

添加回答

回复

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信