解题思路:很简单,就建类,创建,排序就好
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Student[] table = new Student[n];
for (int i = 0; i < n; i++) {
table[i] = new Student(sc.next(), sc.next(), sc.nextInt(), sc.nextInt());
}
sort(table);
for (Student student : table) {
System.out.println(student);
}
sc.close();
}
public static void sort(Student[] table) {
for (int i = 0; i < table.length - 1; i++) {
for (int j = 0; j < table.length - 1 - i; j++) {
if (table[j].score > table[j + 1].score) {
Student temp = table[j];
table[j] = table[j + 1];
table[j + 1] = temp;
}
}
}
}
}
class Student {
String name;
String sex;
int age;
int score;
public Student(String name, String sex, int age, int score) {
this.name = name;
this.sex = sex;
this.age = age;
this.score = score;
}
@Override
public String toString() {
return name + " " + sex + " " + age + " " + score;
}
}
0.0分
0 人评分