展开全部
import java.util.Scanner;
public class Student {
private String stuname = "";
private float stuscore = 0;
public String getStuname() {
e69da5e6ba9062616964757a686964616f31333335316633return stuname;
}
public void setStuname(String stuname) {
this.stuname = stuname;
}
public float getStuscore() {
return stuscore;
}
public void setStuscore(float stuscore) {
this.stuscore = stuscore;
}
public Boolean compare(Student st1, Student st2) {
return st1.stuscore
}
/**
* @param args
*/
public static void main(String[] args) {
Student[] stu = new Student[20];
Scanner scan = new Scanner(System.in);
int nCount = 0;
System.out.println("请输入输入的学生个数:");
nCount = scan.nextInt();
System.out.println("请输入输入的学生姓名和分数:");
int nCurrent = 0;
while (nCurrent
Scanner sca = new Scanner(System.in);
String strLine = sca.nextLine();
String[] strLineArr = strLine.split(" ");
Student st = new Student();
st.setStuname(strLineArr[0]);
st.setStuscore(Float.parseFloat(strLineArr[1]));
stu[nCurrent] = st;
nCurrent++;
}
// 排序
for (int i = 0; i
for (int j = 0; j
if (stu[j].getStuscore() > stu[j + 1].getStuscore()) {
Student tmp = new Student();
tmp.setStuname(stu[j].getStuname());
tmp.setStuscore(stu[j].getStuscore());
stu[j].setStuname(stu[j + 1].getStuname());
stu[j].setStuscore(stu[j + 1].getStuscore());
stu[j + 1].setStuname(tmp.getStuname());
stu[j + 1].setStuscore(tmp.getStuscore());
}
}
}
System.out.println("最高分数:" + stu[nCount - 1].getStuname() + " "
+ stu[nCount - 1].getStuscore());
}
}
运行结果如下: