package 实验报告2;
import java.util.Scanner;
public class student {
// 创建Sutdent类
public static class Student {
int stuScore;
String stuName;
}
public static void main(String[] args) {
Student[] stu = new Student[10];
Scanner input = new Scanner(System.in);
// 錄入用户输入信息
for (int i = 1; i < stu.length; i++) {
stu[i] = new Student();
System.out.println("请输入第" + i++ + "学生姓名:");
stu[i].stuName = input.next();
System.out.println("请输入学生姓名:");
stu[i].stuScore = input.nextInt();
}
//輸出學生信息
System.out.println("学生信息为:");
for (int i = 0; i < stu.length; i++) {
System.out.print(stu[i].stuName + stu[i].stuScore);
}
// 使用for循环,对学生信息进行排序
for (int i = 0; i < stu.length - i - 1; i++) {
if (stu[i].stuScore < stu[i + 1].stuScore) {
int temp;
temp = stu[i].stuScore;
stu[i].stuScore = stu[i + 1].stuScore;
stu[i + 1].stuScore = temp;
}
}
//輸出排序后學生信息
System.out.println("排序后学生信息为:");
for (int i = 0; i < stu.length; i++) {
System.out.print(stu[i].stuName + stu[i].stuScore);
}
}
}
不再热情似火
六道骸
相关分类