Java计算从2000-1-1到2013-7-1的总天数
程序员文章站
2024-03-23 22:50:22
...
package com.p1;
/**
* 2000-1-1到2013-7-1共有多少天
*/
public class Yeshh {
public static void main(String[] args) {
int year=2000;
int month=1;
int sum=0;
while(year<2014){
sum+=365;
if (year%4==0&&year%100!=0||year%400==0) {
sum+=1;
}
year++;
}
while(month<7){
switch (month) {
case 4:
case 6:
sum+=30;
break;
case 2:
sum+=28;
if (year%4==0&&year%100!=0||year%400==0) {
sum+=1;
}
break;
default:
sum+=31;
break;
}
month++;
}
System.out.println(sum);
}
}