class Date1
{
int year,month,day;
public Date1(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
public int compare(Date1 date)
{
return year>date.year ? 1
:year<date.year ? -1
:month>date.month ? 1
:month<date.month ? -1
:day>data.day ? 1
:day<data.day ? -1 : 0; }
}
public class Test1
{
public static void main(String [] args)
{
Date1[] d=new Date1[4];
d[0]=new Date1(2004,11,11);
d[1]=new Date1(2003,11,11);
d[2]=new Date1(2002,11,11);
d[3]=new Date1(2001,11,11);
sort(d);
}
public static void sort(Date1 [] a)
{
for (int i=0;i<a.length ;i++ )
{
for (int j=j+1;j<a.length ;j++ )
{
if (a[i].compare(a[j]<0))
{
int temp ;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
}
{
int year,month,day;
public Date1(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
public int compare(Date1 date)
{
return year>date.year ? 1
:year<date.year ? -1
:month>date.month ? 1
:month<date.month ? -1
:day>data.day ? 1
:day<data.day ? -1 : 0; }
}
public class Test1
{
public static void main(String [] args)
{
Date1[] d=new Date1[4];
d[0]=new Date1(2004,11,11);
d[1]=new Date1(2003,11,11);
d[2]=new Date1(2002,11,11);
d[3]=new Date1(2001,11,11);
sort(d);
}
public static void sort(Date1 [] a)
{
for (int i=0;i<a.length ;i++ )
{
for (int j=j+1;j<a.length ;j++ )
{
if (a[i].compare(a[j]<0))
{
int temp ;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
}
解决方案 »
- 请大家帮我看看hibernate哪里错,myeclipse8.5,mysql数据库
- linux上使用jodconvert转换DOC成PDF乱码?
- 如何根据jprofiler来判断内存泄露
- 麻烦大家了,我请教个关于 Hibernate2.0 加载大字段导致影响速度的问题。
- 请问哪位高人能向我推荐几本关于spring,struct,hibernate源代码分析或技术内幕的书,谢谢
- 关于在mysql中,emoji表情存储问题
- ejb初学者提问,ejb实体bean究竟要写几个类和接口?
- 请问java进程如何进行通信?
- struct 中的一个问题,tomcat4.1+jb9 org.apache.struts.action.RequestProcessor
- struts中setlocale()的问题,牛人帮忙!
- 一道智力面试题目
- 职业人生路上最关键的一本书,100分,希望大家帮忙,拜托了
其中删掉了部分,对照你原来的好好看看。import java.util.*; //引入包
class Date1 implements Comparable //实现接口Comparable
{
int year,month,day;
public Date1(int y,int m,int d) //构造函数
{
year=y;
month=m;
day=d;
}
public int compareTo(Object o) //实现Comparable的函数compareTo()方法
{
Date1 date=(Date1)o;
return year>date.year ? 1
:year <date.year ? -1
:month>date.month ? 1
:month <date.month ? -1
:day>data.day ? 1
:day <data.day ? -1 : 0; }
}
public class Test1
{
public static void main(String [] args)
{
Date1[] d=new Date1[4];
d[0]=new Date1(2004,11,11);
d[1]=new Date1(2003,11,11);
d[2]=new Date1(2002,11,11);
d[3]=new Date1(2001,11,11);
Arrays.sort(d); //调用Arrays.sort(d)方法,实现排序
}
}