class Date {
int day,month,year;
int a[]={31,28,31,30,31,30,31,31,30,31,30,31};
public Date(){
day=1;
month=1;
year=1900;
}
public Date(int d,int m,int y){
day=d;
month=m;
year=y;
}
public boolean IsLeapYear(){
return (year%4==0&&year%100!=0)||(year%400==0);
}
public int daysInMonth(){
if(IsLeapYear()&&month==2)
return a[month-1]+1;
else
return a[month-1];
}
public int daysInYear(){
int sum;
sum=0;
for(int i=0;i<month-1;i++)
{
sum+=a[i];
}
sum+=day;
if(IsLeapYear()&&month>2)
return sum+1;
else
return sum;
}
public String nextDate(){
if(IsLeapYear()&&month==2&&day==a[month-1]+1){
day=1;
month+=1;
}
else if(day==a[month-1]){
if(month==12){
day=1;
month=1;
year+=1;
}
else{
day=1;
month+=1;
}
day+=1;
}
return day+"/"+month+"/"+year;
}
public boolean dateIsValid(){
if(IsLeapYear()&&month==2&&day>0&&day<30)
return true;
else if(month>0&&month<13&&day>0&&day<a[month-1]+1)
return true;
else
return false;
}
}
public class TestDate {
public static void main(String[] args){
Date d = new Date(28,2,2000);
d.dateIsValid();
d.daysInMonth();
d.daysInYear();
}
}
上面的代码编译没错,但是在Run的时候被终止了...
哪位能帮在下看看是什么出问题了