?? datesort.java
字號:
public class DateSort {
public static void main(String[] args) {
Date[] days = new Date[5];
days[0] = new Date(2008,8,8);
days[1] = new Date(2008,7,8);
days[2] = new Date(2007,8,8);
days[3] = new Date(2007,8,9);
days[4] = new Date(2004,2,2);
bubbleSort(days);
print(days);
}
public static Date[] bubbleSort(Date[] a) {
int len = a.length;
for(int i=len-1; i>=1; i--)
for(int j=0; j<=i-1; j++) {
if(a[j].compare(a[j+1]) > 0) {
Date temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
return a;
}
public static void print(Date[] a) {
for(int i=0; i<a.length; i++) {
System.out.println(a[i]);
}
}
}
class Date {
int year,month,day;
public Date(int year,int month,int day) {
this.year = year;
this.month = month;
this.day = day;
}
public int compare(Date a) {
return (year > a.year) ? 1 :
(year < a.year) ? -1 :
(month > a.month) ? 1 :
(month < a.month) ? -1:
(day > a.day) ? 1 :
(day < a.day) ? -1 : 0 ;
}
public String toString() {
return "year-month-day" + "--" + year + ":" + month + ":" +day;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -