package test;
public class Student
{
public String name;
int age;
public Student(String name,int sex)
{
this.name=name;
this.age=sex;
}
//public interface Comparator<T>
class Student implements Comparator<Student>{
private String name;
private int age;
public Student(String name,int sex)
{
this.name=name;
this.age=sex;}
public int compareTo(Student a){
return this.age().compareTo(a.age());
}
}
public String toString() {
return name+":"+age+"岁";
}
public String getName(){
return name;}
public void setName(String name){
this.name=name;}
public int getAge(){
return age;}
public void setAge(int age){
this.age=sex;}
}
}
import java.util.Arrays;
public class Test {
public static void sort(short[] a,
int fromIndex,
int toIndex){
}
public static void main(String[] args) {
Student[] a = new Student[] {
new Student("zhangsan", 20),
new Student("lisi", 22),
new Student("wangwu", 18)
};
Arrays.sort(a);//要求学生按年龄从小到大进行排序
System.out.println(Arrays.toString(a));
}
}
添加回答
举报
0/150
提交
取消