- package com.hu.student;
- import java.util.*;
- public class Main {
- public static void main(String[] agrs) {
- Scanner in = new Scanner(System.in);
- System.out.print("请输入学生的人数:");
- int renshu = in.nextInt();
- System.out.print("请输入课程的数目:");
- int course = in.nextInt();
- int[] sum = new int[renshu];
- int[] avg = new int[renshu];
- String[] arrRenshu = new String[renshu];// 接收学生的人数
- String[] arrCourse = new String[course];// 接收科目的数量
- int[][] number = new int[renshu][course];
- String[] str = new String[renshu]; //学生参数汇总
- for (int i = 0; i < course; i++) {
- System.out.print("请输入第" + (i + 1) + "的科目名称:");
- arrCourse[i] = in.next();
- }
- for (int i = 0; i < renshu; i++) {
- int s = 0;
- String str11 = "";
- System.out.print("请输入第" + (i + 1) + "个学生的名字:");
- arrRenshu[i] = in.next();
- for (int j = 0; j < course; j++) {
- System.out.print("请输入" + arrRenshu[i] + arrCourse[j] + "的成绩:");
- number[i][j] = in.nextInt();
- s += number[i][j];
- str11+= number[i][j]+"\t";
- }
- sum[i] = s;
- avg[i] = s / course;
- str[i] = arrRenshu[i]+"\t"+str11+sum[i]+"\t"+avg[i];
- }
- for(int i=0; i<sum.length-1; i++){
- for(int j=0; j<sum.length-1; j++){
- if(sum[j]<sum[j+1]){
- int t1 = sum[j]; String t2 = str[j];
- sum[j] = sum[j+1]; str[j] = str[j+1];
- sum[j+1] = t1; str[j+1] = t2;
- }
- }
- }
- System.out.print("学生");
- for (int i = 0; i < course; i++) {
- System.out.print("\t" + arrCourse[i]);
- }
- System.out.print("\t总分" + "\t平均分" + "\t排行榜");
- System.out.println();
- for (int i = 0; i < renshu; i++) {
- System.out.print(str[i]+"\t第"+(i+1)+"名");
- System.out.println();
- }
- }
- }
复制代码
还有哪里需要改进的 请多多指教 |
|