效果图
贴个码
//学生管理系统
import java.util.Scanner;
public class score_system {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("请输入有多少学生:");
int students = in.nextInt(); //存储学生人数
System.out.println("请输入有几门学科:");
int subject = in.nextInt(); //存储学科门数
String[] arr_students = new String[students ]; //存储学生的数组
String[] arr_subject = new String[subject]; //存储学科的数组
int[][] score = new int[students][subject]; //存储成绩的二维数组
int[] sum_all = new int[students]; //存储每个人的总成绩的数组
int[] avg_all = new int[students]; //存储每个人的平均成绩的数组
String[] word_all = new String[students]; //存储每个人的内容的数组
//赋值给学科数组
for (int i=0; i<arr_subject.length; i++){
System.out.println("第"+(i+1)+"门学科是:");
arr_subject[i] = in.next();
}
//赋值给学生数组
for (int i=0; i<arr_students.length; i++){
System.out.println("请输入第"+(i+1)+"个学生的姓名:");
arr_students[i] = in.next();
int sum = 0; //存储单个人总成绩;
String word = ""; //将输出的内容连接起来
//赋值给成绩数组
for (int j=0; j<arr_subject.length; j++){
System.out.println(arr_students[i]+arr_subject[j]+"的成绩是:");
score[i][j] = in.nextInt();
sum += score[i][j];
word += score[i][j]+"\t";
}
sum_all[i] = sum; //将每个人的总成绩赋值给数组
avg_all[i] = sum/subject; //将每个人的平均成绩赋值给数组
word_all[i] = arr_students[i]+"\t"+word+sum_all[i]+"\t"+avg_all[i]+"\t"; //将每个人成绩和总分与平均分拼接
}
//用冒泡排序
for (int i=0; i<arr_students.length-1; i++){
for (int j=0; j<arr_students.length-1; j++){
if (sum_all[j]<sum_all[j+1]){
int t = sum_all[j]; String a = word_all[j]; //根据总分排名,总分位置改变,其他内容也跟着改变
sum_all[j] = sum_all[j+1]; word_all[j] = word_all[j+1];;
sum_all[j+1] = t; word_all[j+1] = a;
}
}
}
//输出标题
System.out.print("学生\t");
for (int i=0; i<arr_subject.length; i++){
System.out.print(arr_subject[i]+"\t");
}
System.out.print("总分\t"+"平均分\t"+"排行榜");
System.out.println();
//输出名字+成绩+总分+平均分+排行榜
for (int i=0; i<arr_students.length; i++){
System.out.println(word_all[i]+"第"+(i+1)+"名");
}
}
}