2个回答
推荐于2017-12-16
展开全部
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());
}
}
}
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());
}
}
}
追问
不是这样的。我们老师要求的是原创,他给画了大概样子的。新手造孽啊,大三才学数据库,现在才大二就要我们做。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询