import java.util.Scanner;
public class StudentInAndOut {
private String name;
private long grade;
public long getGrade() {
return grade;
}
public void setGrade(long grade) {
this.grade = grade;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString(){
return this.name;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入学生数");
int stuNumT = sc.nextInt();
StudentInAndOut objArr[] = new StudentInAndOut[stuNumT];
for(int i = 0; i < objArr.length; i++){
objArr[i] = new StudentInAndOut();
System.out.println("请输入第" + (i+1) + "个学生的姓名");
String name = sc.next();
objArr[i].setName(name);
System.out.println("请输入第" + (i+1) + "个学生的成绩");
long grade = sc.nextLong();
objArr[i].setGrade(grade);
}
System.out.println("打印开始:");
for(int i = 0; i < objArr.length; i++){
for(int j = i+1; j < objArr.length; j++){
if(objArr[i].getGrade() < objArr[j].getGrade()){
StudentInAndOut s = new StudentInAndOut();
s = objArr[i];
objArr[i] = objArr[j];
objArr[j] = s;
}
}
}
for(int i=0; i < objArr.length; i++){
System.out.println(objArr[i].getName()+"的成绩是:"+objArr[i].getGrade());
}
}
}
import java.util.Scanner;
import java.util.Map;
import java.util.TreeMap;
import java.util.Iterator;
public class PrintStuTest {
public static void main(String[] args) {
System.out.println("请输入学生数:");
Scanner scan = new Scanner(System.in);
int count = scan.nextInt();
Map
int time = 0;
while(time
String name = scan.next();
float sco = scan.nextFloat();
stu.put(name, sco);
time++;
}
Iterator
String[] str = new String[count];
time = 0;
while(iter.hasNext()) {
str[time] = iter.next();
time++;
}
System.out.println("成绩降序,学生姓名:");
for(int i=0; i
}
}
}
//输入姓名和成绩需用空格隔开,成绩为 float 型
你的问题描述的不是很清楚。有没有数据库,而且输入的学生数量、学生姓名、成绩到底有什么用?