java code 
class Date1{
  int year;
  int month;
  int day;
  Date1 (int y,int m,int d){
    year=y;
    month=m;
    day=d;
  }
  public int compare(Date1 d){
    return year>d.year? 1
          :year<d.year? -1
          :month>d.month? 1
          :month<d.month? -1
          :day>d.day? 1
          :day<d.day? -1:0;
  }
 }
public class TestBs{
  public static void main(String[] args){
    Date1 [] d=new Date1 [5];
    d[0]=new Date1(2007,7,8);
    d[1]=new Date1(2008,8,8);
    d[2]=new Date1(2005,8,1);
    d[3]=new Date1(2004,6,3);
    d[4]=new Date1(2008,6,19);
    for(int i=d.length-1;i<=1;i--){
      for(int j=0;j<=i-1;j++){
        if(d[j].compare(d[j+1])>0){
          Date1 temp=d[j];
              d[j]=d[j+1];
              d[j+1]=temp;
        }
      }
    }
    System.out.print("从小到大排序:");
    for(int i=0;i<d.length;i++){
    System.out.print(" "+d[i]);
    }
  }
}
运行结果:
从小到大排序: Date1@bd0108 Date1@8ed465 Date1@11a698a Date1@107077e Date1@7ced01
[color=#FF0000]怎么出现这个结果???[/color]

解决方案 »

  1.   

    System.out.print(" "+d[i]); 这里直接打印出对象了. 后面直接跟的是Hashcode .你如果用 java.util.*下面Date的话. 可以直接.但是这个是你自己定义的.没有复写toString方法.所以没办法.. 改成这样:System.out.print(" " + d[i].year +d[i].month+d[i].day);结果:从小到大排序: 200778 200888 200581 200463 2008619Ms你的冒泡没有奏效哦 . .  呵呵.. 你可以看见结果不是很 美观..你可以在中间做点动作之类的. 加个"年""月"之类的.  就OK了.
      

  2.   

    d[i]其实是一个date对象
    System.out.print(" "+d[i]); 打印出的的是这个对象的地址,
      

  3.   


    System.out.print("从小到大排序:");
    for (int i = 0; i < d.length; i++) {
    System.out.print(" " + d[i].toDate1());
    }         public String toDate1() {
    return year + "年" + month + "月" + day + "日";
    }