我不知道哪里错了。。
import java.util.Scanner;
public class NewClass {
Student student = new Student();
int n;
public void init(Student student) {
System.out.println("How many students do you want to input?");
Scanner str = new Scanner(System.in);
n = str.nextInt();
student.scores = new int[n];
student.number = new String[n];
student.name = new String[n];
System.out.println("Please input " + n + " students' number,name and scores");
Scanner string = new Scanner(System.in);
Scanner string1 = new Scanner(System.in);
Scanner string2 = new Scanner(System.in);
for (int i = 0; i < n; i++) {
student.number[i] = string.nextLine();
student.name[i] = string1.nextLine();
student.scores[i] = string2.nextInt();
}
sort(student);
}
public void sort(Student student) {
String numbertemp, nametemp;
int scorestemp;
for (int i = 0; i < n - 1; i++) {
for (int j = 1; j < n; j++) {
if (
student.scores[i] < student.scores[j]) {
numbertemp = student.number[i];
student.number[i] = student.number[j];
student.number[j] = numbertemp;
nametemp = student.name[i];
student.name[i] = student.name[j];
student.name[j] = nametemp;
scorestemp = student.scores[i];
student.scores[i] = student.scores[j];
student.scores[j] = scorestemp;
}
}
}
output(student);
}
public void output(Student student) {
for (int i = 0; i < n; i++) {
System.out.println(student.name[i]);
}
}
public static void main(String args[]) {
NewClass application = new NewClass();
application.init(student);
}
}
class Student{
String number[];
String name[];
int scores[];
Student(String number[],String name[],int scores[]){
this.name = name;
this.number = number;
this.scores = scores;
}
Student() {
throw new UnsupportedOperationException("Not yet implemented");
}
}
------解决方案--------------------
刚运行了一下你的代码发现不能运行 给你改了一下可以运行了 希望对你有帮助
import java.util.Scanner;
public class NewClass {
Student student = new Student();
int n;
public void init() {//这里给你改了 这里不能再定义student了
System.out.println("How many students do you want to input?");
Scanner str = new Scanner(System.in);
n = str.nextInt();
student.scores = new int[n];
student.number = new String[n];
student.name = new String[n];
System.out.println("Please input " + n + " students' number,name and scores");
Scanner string = new Scanner(System.in);
Scanner string1 = new Scanner(System.in);
Scanner string2 = new Scanner(System.in);
for (int i = 0; i < n; i++) {
student.number[i] = string.nextLine();
student.name[i] = st