错误很多,自己对照把,应该是完成两个日期差多少天的功能把。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])));
}
}
{
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])));
}
}
解决方案 »
- 问一下,int类型不是能转换成char型吗,为什么这里会报错?而下一条代码不报错?
- Java怎么监听远程服务器中的某个端口是否开启
- 数流行语言 还看今朝 O北京额草他、
- SWING组件问题
- 我在eclips里 写 List l1 = new LinkedList();为什么错误啊?
- 通过url将ftp上的文件写入本地时出现了问题
- ****eclipse高手请进,菜鸟问题,急待解决!******
- 多线程下的LinkedList类问题。
- 怎么用JavaScript屏蔽打开的新网页右上角的关闭(X)按钮
- java.util.Date中syntax:{}是什么意思?
- 计事本的例子,和能打开.txt格式的文件的程序的例子
- 兄弟门啊我可算找到提问了啊!! 郁闷我好几天了也没有找到提问!高兴 !不过我不会给分啊
Line28: dd1,dd2使用前应该初始化
Line92: d,m,y不能被静态访问
integer不认识
Line94: integer不认识
Last: 缺少"}"
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);
}
}
<<
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();
}
}
}
>>