错误很多,自己对照把,应该是完成两个日期差多少天的功能把。public class  mydata
{
int y,m,d;
mydata(int y1,int m1,int d1)
   {
y=y1;
m=m1;
d=d1;
   }
mydata()
    {
y=1900;
m=1;
d=1;
    }
public boolean equals(mydata x){return(y==x.y&&m==x.m&&d==x.d);}
public int compareto(int y,int m,int d)
{
int yy1,yy2,mm1,mm2,dd1,dd2;
int a,s;
if(y<=this.y)
       {
      yy1=y;
      yy2=this.y;
      mm1=m;
      mm2=this.m;
      dd1=d;
       dd2=this.d;
       }
else
       {
      yy2=y;
      yy1=this.y;
      mm2=m;
      mm1=this.m;
       dd2=d;
      dd1=this.d;
       }
       
       s=dd2-dd1;
for(int x=yy1;x<=yy2;x++)
for(int i=1;i<=12;i++)
{
if(x<=yy1&&i<=mm1) continue;
if(x>=yy2&&i>=mm2) continue;
if(x<=yy2&&i<mm2)
                         {
if(x%4==0&&x%100==0&&x%400==0)
    {
switch(i){
case 2: a= 29;s+=a;break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:a=31;s+=a;break;
case 4:
case 6:
case 9:
case 11:a=30;s+=a;break;}
    }
else
    {
switch(i){
case 2: a= 28;s+=a;break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:a=31;s+=a; break;
case 4:
case 6:
case 9:
case 11:a=30;s+=a;break;
    }}
                         }
}
return s;
}
public static void main(String args[])
{mydata wt=new mydata(Integer.parseInt(args[0]),Integer.parseInt(args[1]),Integer.parseInt(args[2]));
System.out.println(wt.compareto(Integer.parseInt(args[3]),Integer.parseInt(args[4]),Integer.parseInt(args[5])));
}
}

解决方案 »

  1.   

    先说一些:
    Line28: dd1,dd2使用前应该初始化
    Line92: d,m,y不能被静态访问
            integer不认识
    Line94: integer不认识
    Last:   缺少"}"
      

  2.   

    我程序改了改不过还是有一个错误 不知道怎么改了帮帮我吧!
    public class  mydata
    {
    int y,m,d;
    mydata(int y1,int m1,int d1)
       {
    y=y1;
    m=m1;
    d=d1;
       }
    mydata()
        {
    y=1900;
    m=1;
    d=1;
        }
    public boolean equals(mydata x){return(y==x.y&&m==x.m&&d==x.d);}
    public int compareto(mydata w)
    {
    int yy1,yy2,mm1,mm2,dd1,dd2;
    int a,s;
    if(y<=w.y)
           {
          yy1=y;
          yy2=w.y;
          mm1=m;
          mm2=w.m;
          dd1=d;
           dd2=w.d;
           }
    else
           {
          yy2=y;
          yy1=w.y;
          mm2=m;
          mm1=w.m;
           dd2=d;
          dd1=w.d;
           }
    s=dd2-dd1;
    for(int x=yy1;x<=yy2;x++)
    for(int i=1;i<=12;i++)
    {
    if(x<=yy1&&i<=mm1) continue;
    if(x>=yy2&&i>=mm2) continue;
    if(x<=yy2&&i<mm2)
                             {
    if(x%4==0&&x%100==0&&x%400==0)
        {
    switch(i){
    case 2: a= 29;s+=a;break;
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:a=31;s+=a;break;
    case 4:
    case 6:
    case 9:
    case 11:a=30;s+=a;break;}
        }
    else
        {
    switch(i){
    case 2: a= 28;s+=a;break;
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:a=31;s+=a; break;
    case 4:
    case 6:
    case 9:
    case 11:a=30;s+=a;break;
        }}
                             }
    }
    return s;
    }
    public static void main(String args[])
    {
    mydata wt=new mydata(Integer.parseInt(args[0]),Integer.parseInt(args[1]),Integer.parseInt(args[2]));
    int ss=wt.compareto(Integer.parseInt(args[3]),Integer.parseInt(args[4]),Integer.parseInt(args[5]));
       System.out.println(ss);
    }
                                                                    }
      

  3.   

    唉,太费力了,俺帮你随便改写了一下。。
    <<
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;final public class MyDate implements Comparable<MyDate> {
        private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd");
        final int year;
        final int month;
        final int day;    MyDate(int year, int month, int day) {
            this.year = year;
            this.month = month;
            this.day = day;
        }    MyDate() {
            this(1900,1,1);
        }    public boolean equals(Object o) {
            if(o == this) return true;
            if(!(o instanceof MyDate)) return false;
            MyDate that = (MyDate)o;
            return (year==that.year) && (month==that.month) && (day==that.day);
        }    public int hashCode() {
            int result = 17;
            result = 37 * result + year;
            result = 37 * result + month;
            result = 37 * result + day;
            return result;
        }    /**
         * Compare to <code>MyDate</code> objects.
         * @param o Another <code>MyDate</code> to compare with this.
         * @return Compare result integer.
         * @throws NullPointerException If passing in null <code>MyDate</code> object.
         * @throws RuntimeException If parse <code>SimpleDateFormat</code> error.
         */
        public int compareTo(MyDate o) {
            Date thisDate = toDate();
            Date thatDate = o.toDate();
            return thisDate.compareTo(thatDate);
        }    // private :
        private Date toDate() {
            try {
                return FORMAT.parse(year+"-"+month+"-"+day);
            } catch(ParseException ex) {
                throw new RuntimeException();
            }
        }
    }
    >>