public class DateSort{
public static void main(String[] args){
Date[] days= new Date[5];
days[0] = new Date (2007,2,2);
days[1] = new Date (2004,6,1);
days[2] = new Date (2006,9,7);
days[3] = new Date (2006,6,7);
days[4] = new Date (2002,5,4);
bubbleSort(days);
for(int i = 0; i < days.length; i++){
System.out.print(days[i]);
}
}
public static Date[] bubbleSort(Date[] a){
int len = a.length;
for(int i = len-1; i > 0; 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;
}
}
}
retrun a;
}
}
class Date{ private int year,month,day;
Date(int y,int m,int d){
year = y;
month = m;
day = d;
}
public int compare(Date Date){
return year > Date.year ? 1
: year < Date.year ? -1
: month > Date.month ? 1
: month < Date.month ? -1
: day > Date.day ? 1
: day < Date.day ? -1 : 0;
}
}
DateSort.java:27: 找不到符号
符号: 类 retrun
位置: 类 DateSort
retrun a;
^
DateSort.java:27: 已在 bubbleSort(Date[]) 中定义 a
retrun a;
^
2 错误
public static void main(String[] args){
Date[] days= new Date[5];
days[0] = new Date (2007,2,2);
days[1] = new Date (2004,6,1);
days[2] = new Date (2006,9,7);
days[3] = new Date (2006,6,7);
days[4] = new Date (2002,5,4);
bubbleSort(days);
for(int i = 0; i < days.length; i++){
System.out.print(days[i]);
}
}
public static Date[] bubbleSort(Date[] a){
int len = a.length;
for(int i = len-1; i > 0; 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;
}
}
}
retrun a;
}
}
class Date{ private int year,month,day;
Date(int y,int m,int d){
year = y;
month = m;
day = d;
}
public int compare(Date Date){
return year > Date.year ? 1
: year < Date.year ? -1
: month > Date.month ? 1
: month < Date.month ? -1
: day > Date.day ? 1
: day < Date.day ? -1 : 0;
}
}
DateSort.java:27: 找不到符号
符号: 类 retrun
位置: 类 DateSort
retrun a;
^
DateSort.java:27: 已在 bubbleSort(Date[]) 中定义 a
retrun a;
^
2 错误
public static void main(String[] args){
Date[] days= new Date[5];
days[0] = new Date (2007,2,2);
days[1] = new Date (2004,6,1);
days[2] = new Date (2006,9,7);
days[3] = new Date (2006,6,7);
days[4] = new Date (2002,5,4); bubbleSort(days);
for(int i = 0; i < days.length; i++){
System.out.print(days[i]);
}
} public static Date[] bubbleSort(Date[] a){
int len = a.length;
for(int i = len-1; i > 0; 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;
}
}class Date{ private int year,month,day;
Date(int y,int m,int d){
year = y;
month = m;
day = d;
}
public int compare(Date Date){
return year > Date.year ? 1
: year < Date.year ? -1
: month > Date.month ? 1
: month < Date.month ? -1
: day > Date.day ? 1
: day < Date.day ? -1 : 0;
}
}
那个提示很明确啊,你的return关键字,打错了。你给写成retrun了。我看了一下,楼主的Date类,没有重写toString方法,所以,会显示对象的内存地址。
改为void试试
public void bubbleSort(Date[] a){ }
public static void main(String[] args){
Date[] days= new Date[5];
days[0] = new Date (2007,2,2);
days[1] = new Date (2004,6,1);
days[2] = new Date (2006,9,7);
days[3] = new Date (2006,6,7);
days[4] = new Date (2002,5,4); bubbleSort(days);
for(int i = 0; i < days.length; i++){
System.out.print(days[i]);
}
} public static Date[] bubbleSort(Date[] a){
int len = a.length;
for(int i = len-1; i > 0; 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; //楼上return写错了,写成retrun了
}
}
class Date{ private int year,month,day;
Date(int y,int m,int d){
year = y;
month = m;
day = d;
}
public int compare(Date Date){
return year > Date.year ? 1
: year < Date.year ? -1
: month > Date.month ? 1
: month < Date.month ? -1
: day > Date.day ? 1
: day < Date.day ? -1 : 0;
}
}
现在都用MyEclipse