题目描述:键盘输入多个日期,日期之间使用“,”隔开,由于输入的日期顺序可能是乱着的,你需要按照自然顺序输出已排序的日期
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Scanner;
//自定义日期类,定义比较规则
class myData {
int year, mounth, day;
public myData(int year,int mounth,int day){
this.year = year;
this.mounth = mounth;
this.day = day;
}
public int compare(myData data) {
return year>data.year ? 1 : year < data.year ? -1 :
mounth > data.mounth ? 1 : mounth < data.mounth ? -1 :
day > data.day ? 1 : day