date(int year, int month, int day){
this.year = year;
this.month = month;
this.day = day;
}
date(int month, int day){
this.month = month;
this.day = day;
year = 2000;
}
public static void setMonth(int monthset){
month = monthset;
}
public static void setDay(int dayset){
day = dayset;
}
public static void setYear(int yearset){
year = yearset;
}
public static int getMonth(){
return month;
}
public static int getDay(){
return day;
}
public static int getYear(){
return year;
}
public static int selectNian(){
int a =date.getYear();
int d2;
if((a%4==0&&a%100!=0)||a%400==0){
d2 = 29;
System.out.println("今年是闰年二月有29天");
}else { d2 = 28;
System.out.println( "今年不是闰年二月有28天");
}
return d2;
}
public static int dijitian(date d){ //这里可以用数组 也可以写算法 但是我当初写的时候 用算法 算月份 搞了十多分钟没搞出来 就一个愤怒 直接打出来了 嘻嘻
int n = d.selectNian();
int x = d.getMonth();
int num = 0;
if(x ==1){ num = d.getDay();}
else if(x ==2){num = 31+d.getDay() ;}
else if(x ==3){num = 31+n+d.getDay();}
else if(x ==4){num = 62+n+d.getDay();}
else if(x ==5){num = 92+n+d.getDay();}
else if(x ==6){num = 123+n+d.getDay();}
else if(x ==7){num = 153+n+d.getDay();}
else if(x ==8){num = 184+n+d.getDay();}
else if(x ==9){num = 215+n+d.getDay();}
else if(x ==10){num = 245+n+d.getDay();}
else if(x ==11){num = 276+n+d.getDay();}
else if(x ==12){num = 306+n+d.getDay();}
else{System.out.println("对不起,您输入的参数有误");}
return num;
}
public static date input(){ //这里 你自己写吧 我那个写好的代码 找不到了 不想写了 你直接调用键盘输出 然后上面的年份有构造函数 直接调用就OK了 我懒得弄了
BufferedReader br = new BufferedReader(new InputStreamReader());
}
}
public class DemoDay{
public static void main(String[]args){
date d1 = new date(1900,7,7);
int c = date.dijitian(d1);
System.out.println(c);
}
} 作者: 刘胜寒 时间: 2013-5-14 08:03