关于按照从小到大的顺序 输出的问题

题目:

img


样例输入:
5
7 58 55 88 74 95 98 86
3 90 65 78
2 70 58
5 17 62 69 83 32
9 51 66 42 98 13 85 87 97 60
样例输出:
17 62 69 83 32
70 58
51 66 42 98 13 85 87 97 60
90 65 78
58 55 88 74 95 98 86

问题:不知道如何按照平均成绩的大小输出输入的数据

package test;
import java.util.Arrays;
import java.util.Scanner;
public class Jiaoxue {
    public void main (String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][]  a =new int [n][];
        int[] sum = new int [n];
        int[] average = new int [n];
        for(int i = 0;ifor(int j=0 ;j0];j++) {
                a[i][j] =sc.nextInt();
            }
        }
        for(int i=0;ifor(int j=1;j0];j++)
            {
                sum[i]=sum[i]+a[i][j];
            }
            average[i]=sum[i]/a[i][0];
        }
    }
    
}


    public static void main(String[] args) {
        //接收输入数据,并计算平均值
        Scanner sc = new Scanner(System.in);
        int teacherCount = sc.nextInt();
        int [][] arr = new int[teacherCount][];
        int [] avg = new int[teacherCount];
        for (int i = 0 ; i < teacherCount; i ++) {
            int studentCount = sc.nextInt();
            int [] scoreArr = new int[studentCount];
            int sum = 0;
            for (int j = 0; j < studentCount; j ++) {
                int score = sc.nextInt();
                scoreArr[j] = score;
                sum+=score;
            }
            arr[i] = scoreArr;
            avg[i] = sum/studentCount;
        }
        System.out.println("成绩矩阵");
        for (int i = 0; i < teacherCount; i++) {
            int [] scoreArr = arr[i];
            for (int j = 0; j<scoreArr.length; j++) {
                System.out.print(scoreArr[j] + " ");
            }
            System.out.println();
        }
        //将平均分数下标存储到数组
        int [] sort = new int[avg.length];
        for(int i = 0; i < sort.length; i++) {
            sort[i] = i;
        }
        //冒泡排序,排序的同时调整平均分下标
        for(int i = 1; i < avg.length ; i++){
            for(int j = 0; j < i ; j++) {
                if (avg[j] > avg[i]) {
                    int tem = avg[i];
                    avg[i] = avg[j];
                    avg[j] = tem;

                    int _tem = sort[i];
                    sort[i] = sort[j];
                    sort[j] = _tem;
                }
            }

        }
        System.out.println("输出");
        for (int i = 0; i < sort.length; i++) {
            int [] scoreArr = arr[sort[i]];
            for (int j = 0; j<scoreArr.length; j++) {
                System.out.print(scoreArr[j] + " ");
            }
            System.out.println();
        }
    }