Arrays out()排序
public class Student {
private String name;
private int level;
public Student(String name, int level) {
super();
this.name = name;
this.level = level;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
@Override
public String toString() {
return "Student [name=" name ", level=" level "]";
}
}
import java.util.Arrays;
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Student[] a= {
new Student("赵", 24),
new Student("钱", 11),
new Student("孙", 1),
new Student("李", 6),
new Student("周", 17),
new Student("吴", 35),
new Student("郑", 10),
new Student("王", 20) };
Arrays.sort(a);
for (Student x : a)
System.out.println(x);
System.out.println();
问题出在哪里?
很明显的问题,你没有实现Student的Comparable接口
你对Student排序,它以什么方式排序呢,是姓名还是level,你要指定的
具体可参考任何一本教材有关JAVA类排序部分
对初学生,人个的建议是自己写排序方法(练习中常用的就是冒泡法)
答:详情>>
答:详情>>
问:帮忙翻译帮忙翻译 本文从员工教育和培训的概念入手,通过员工教育和培训目的、内容、...
答:In this paper, staff education and training start with the concept, through staf...详情>>
问:请帮我翻译请帮我翻译参加法律(基础科段)专业专科高等教育自学考试 谢谢!
答:taking part in self-taught examination for higher education ----law major (junio...详情>>