在个程序什么错误
public class Time {int day,yesterday,tomorrow,month,lastmonth;
int nextmonth,year,lastyear,nextyear;
Time(int y,int m,int d){
year=y;
month=m;
day=d;
}
boolean leap=false;
leap=(year%400==0)|(year%100!=0)&(year%4==0);
public void shijian(){
switch(month)
{
case 1:
if(1<day<31)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==1)
lastmonth=12;yesterday=31;lastyear=year-1;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==31)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month+1;tomorrow=1;nextyear=year;
case 4:
case 6:
case 8:
case 9:
case 11:
if(1<day<30)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==1)
lastmonth=month-1;yesterday=31;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==30)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month+1;tomorrow=1;nextyear=year;
case 5:
case 7:
case 10:
if(1<day<31)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==1)
lastmonth=month-1;yesterday=30;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==31)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month+1;tomorrow=1;nextyear=year;
case 12:
if(1<day<31)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==1)
lastmonth=month-1;yesterday=30;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==31)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=1;tomorrow=1;nextyear=year+1;
case 2:
if(leap){
if(1<day<29)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==1)
lastmonth=month-1;yesterday=31;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==29)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month+1;tomorrow=1;nextyear=year;
}
else
{
if(1<day<28)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==1)
lastmonth=month-1;yesterday=31;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==28)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month+1;tomorrow=1;nextyear=year;
}
case 3:
if(1<day<31)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
if(day==1)
if(leap){
lastmonth=month-1;yesterday=29;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
}
else{
lastmonth=month-1;yesterday=28;lastyear=year;
nextmonth=month;tomorrow=day+1;nextyear=year;
}
if(day==31)
lastmonth=month;yesterday=day-1;lastyear=year;
nextmonth=month+1;tomorrow=1;nextyear=year;
}
}
public void print(){
System.out.println("今天"+year+" "+month+" "+day);
System.out.println("昨天"+lastyear+" "+lastmonth+" "+yesterday);
System.out.println("明天"+nextyear+" "+nextmonth+" "+tomorrow);
}
public static void main(String[] args) {
Time a=new Time(2000,1,22);
a.print();
}
}
----------------解决方案--------------------------------------------------------
错误太多了
leap=(year%400==0)|(year%100!=0)&(year%4==0);
就不对,
if(1<day<31)
在JAVA中不是能这要写的,应该写成if(day>1&&day<31)
----------------解决方案--------------------------------------------------------
谢谢楼上的,我已经按你的方法改过来了
----------------解决方案--------------------------------------------------------
不用谢,以后多多光临就可以了
----------------解决方案--------------------------------------------------------