java如何计算某年某日在一年中是第几天?

2024-11-26 02:02:21
推荐回答(1个)
回答1:

class CalTianShu{
public static int cal(int year,int month,int day){
int sum=0;
for(int i=1;i switch(i){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:sum+=31; break;
case 4:
case 6:
case 9:
case 11:sum+=30; break;
case 2: if(((year%4==0) & (year%100!=0)) | (year%

400==0))sum+=29; else sum+=28;
}
}
return sum=sum+day;
}
public static void main(String[] args){
int val;
val=cal(2006,2,31);
System.out.println("该天是当年中的第"+val+"天");
}
}