package arrayStudent;import java.util.Scanner;public class StudentManageSystem {public static void main(String[] args) {//导入扫描仪Scanner in = new Scanner(System.in);//提示信息System.out.println("请输入学生的人数:");int studentNum = in.nextInt();System.out.println("请输入课程数目:") ;int courseNum = in.nextInt();/** * 定义变量及数组 *///总分int sum = 0;//平均分double avg = 0;//存放学生姓名String [] students = new String[studentNum];//存放课程名称String [] courses = new String[courseNum];//存放学生每门课的成绩int [] [] members = new int[studentNum][courseNum];//存放总分的数组int [] sums = new int[studentNum];//存放平均分的数组int [] avgs = new int [studentNum];//存放整合之后的每一行String [] all= new String[studentNum];/** * 循环录入课程名称 */for(int i = 0;i<courses.length;i++){System.out.println("请输入第"+(i+1)+"门课:");courses[i] = in.next();}/** * */for(int i = 0;i<students.length;i++){//循环录入学生的姓名System.out.println("请输入第"+(i+1)+"个学生的姓名:");students[i] = in.next();for(int j =0;j<courses.length;j++){//循环录入学生的成绩System.out.println("请输入"+students[i]+"的"+courses[j]+"成绩:");members[i][j] = in.nextInt();}}/** * 输出的标准 */System.out.print("学生");for(int i = 0;i<courses.length;i++){System.out.print("\t"+courses[i]);}System.out.print("\t总分"+"\t平均分");for(int i = 0;i<students.length;i++){String str ="";System.out.println();for(int j = 0;j<members.length;j++){//整合学生的成绩str += members[i][j]+"\t";//求出成绩的总分sum +=members[i][j];}//将总分存入数组 sums[i] = sum; //将平均分存入数组 avgs[i] = (int)(sum/courseNum); //循环之后,让总分归零 sum = 0; //整合结果存进数组 all[i] = students[i]+"\t"+str+""+sums[i]+"\t"+avgs[i];}/** * 利用总分排序, * 总分交换的时候,整合之后的每行都交换, * 即交换学生的所有信息。 */for(int i = 0;i<all.length-1;i++){for(int j = 0; j<all.length-1;j++){if(sums[j]<sums[j+1]){int t1 = sums[j]; String t2 = all[j];sums[j] = sums[j+1]; all[j] = all[j+1];sums[j+1] = t1; all[j+1] = t2;}}}/** * 循环输出 */for(int i = 0; i<all.length;i++){System.out.print(all[i]);}}}
数组学生管理
最新推荐文章于 2023-04-09 19:40:48 发布