public class time {
int year,month,day;
time(int y,int m,int d){
year=y;
month=m;
day=d;
}
Boolean shifou(){
if(year%100==0&&year%400==0)
return true ;
else if(year%100!=0&&year%4==0)
return true;
else return false;
}
int day(){
int b=0;
if(this.shifou()==true)
{
switch(month)
{
case 1:b=day ;
case 2:b=30+day;
case 3:b=59+day;
case 4:b=90+day;
case 5:b=120+day;
case 6:b=151+day;
case 7:b=181+day;
case 8:b=212+day;
case 9:b=253+day;
case 10:b=283+day;
case 11:b=314+day;
case 12:b=344+day;
default:System.out.println("输入错误");
}
}
else
switch(month)
{
case 1:b=day ;
case 2:b=30+day;
case 3:b=59+day;
case 4:b=90+day;
case 5:b=120+day;
case 6:b=151+day;
case 7:b=181+day;
case 8:b=212+day;
case 9:b=253+day;
case 10:b=283+day;
case 11:b=314+day;
case 12:b=344+day;
default:System.out.println("输入错误");
}
return b;
}
public static void main(String[]args)
{
time ab=new time(2000,4,5);
System.out.println(ab.shifou());
System.out.println(ab.day());
}
}谢谢
public class Time {
int year,month,day;
Time(int y,int m,int d){
year=y;
month=m;
day=d;
}
Boolean shifou(){
if(year%100==0&&year%400==0)
return true ;
else if(year%100!=0&&year%4==0)
return true;
else return false;
}
int day(){
int b=0;
if(this.shifou()==true){
switch(month){
case 1:b=day ;break;
case 2:b=30+day;break;
case 3:b=59+day;break;
case 4:b=90+day;break;
case 5:b=120+day;break;
case 6:b=151+day;break;
case 7:b=181+day;break;
case 8:b=212+day;break;
case 9:b=253+day;break;
case 10:b=283+day;break;
case 11:b=314+day;break;
case 12:b=344+day;break;
default:System.out.println("输入错误");
}
}else{
switch(month){
case 1:b=day ; break;
case 2:b=30+day;break;
case 3:b=59+day;break;
case 4:b=90+day;break;
case 5:b=120+day;break;
case 6:b=151+day;break;
case 7:b=181+day;break;
case 8:b=212+day;break;
case 9:b=253+day;break;
case 10:b=283+day;break;
case 11:b=314+day;break;
case 12:b=344+day;break;
default:System.out.println("输入错误");
}
}
return b;
}
public static void main(String[]args){
Time ab=new Time(2000,4,5);
System.out.println(ab.shifou());
System.out.println(ab.day());
}
}
{
case 1:b=day ;break;
case 2:b=30+day;break;
......
int year,month,day;
Time(int y,int m,int d){
year=y;
month=m;
day=d;
}
Boolean shifou(){
if(year%100==0&&year%400==0)
return true ;
else if(year%100!=0&&year%4==0)
return true;
else return false;
}
int day(){
int b=0;
if(this.shifou()==true){
switch(month){
case 1:b=day ;break;
case 2:b=30+day;break;
case 3:b=59+day;break;
case 4:b=90+day;break;
case 5:b=120+day;break;
case 6:b=151+day;break;
case 7:b=181+day;break;
case 8:b=212+day;break;
case 9:b=253+day;break;
case 10:b=283+day;break;
case 11:b=314+day;break;
case 12:b=344+day;break;
default:System.out.println("输入错误");
}
}else{
switch(month){
case 1:b=day ; break;
case 2:b=30+day;break;
case 3:b=59+day;break;
case 4:b=90+day;break;
case 5:b=120+day;break;
case 6:b=151+day;break;
case 7:b=181+day;break;
case 8:b=212+day;break;
case 9:b=253+day;break;
case 10:b=283+day;break;
case 11:b=314+day;break;
case 12:b=344+day;break;
default:System.out.println("输入错误");
}
}
return b;
}
public static void main(String[]args){
Time ab=new Time(2000,4,5);
System.out.println(ab.shifou());
System.out.println(ab.day());
}
}
private int Sum(int y,int m,int d)
{
int a[12]={0,31,28,31,30,31,30,31,31,30,31,30};
int i,sum=0;
for(i=1;i<m;i++)
{
sum+=a[i];
}
sum+=d;
if((y%4==0&&y%100!=0||y%400==0)&&m>2)
{
sum++;
}
return sum;
}
sum++ 就不行了