爱问知识人 爱问教育 医院库

Arrays out()排序

首页

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();
问题出在哪里?

提交回答

全部答案

    2018-05-29 04:59:37
  • 很明显的问题,你没有实现Student的Comparable接口
    你对Student排序,它以什么方式排序呢,是姓名还是level,你要指定的
    具体可参考任何一本教材有关JAVA类排序部分
    对初学生,人个的建议是自己写排序方法(练习中常用的就是冒泡法)

    I***

    2018-05-29 04:59:37

类似问题

换一换
  • 外语学习 相关知识

  • 教育培训
  • 教育科学
  • 教育考试

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):