java数组实现对象排序

import java.util.Scanner;
public class Student {
    String Name;
    int age;
    int grade;
    public void shuchu(){
        System.out.println("姓名"+Name+"年龄"+age+"成绩"+grade);
    }
    public static void sort(Student b[]){
        int i,j;
        Student temp;
        for(i=1;i<=9;i++){
            for(j=0;j<9;j++){
                if (b[j].grade>b[j+1].grade){
                    temp=b[j];
                    b[j]=b[j+1];
                    b[j+1]=temp;
                }
            }
        }

    }

    public static void main(String[] args) {
        Student a[]=new Student[100];
        Scanner input = new Scanner(System.in);
        System.out.println("请输入当前学生的分数");
        for(int i=0;i<=9;i++){
            a[i]=new Student();
            a[i].Name ="学生"+i;
            a[i].age =20;
            a[i].grade=input.nextInt();
        }
        for(int i=0;i<=9;i++){
            a[i].shuchu();
        }
        sort(a);
        System.out.println();
        for(int i=0;i<=9;i++){
            a[i].shuchu();
        }
    }

}

你可能感兴趣的:(java,开发语言,jvm)