- public class Frist {
- public static void main(String[] args)
- {
- judge(2013,7);
- }
-
- public static void judge(int year,int month)
- {
- int count = 0; //计数器来统计闰年的个数
- int yearD = 0;
- int monthD=0;
- int[] leap ={0,31,29,31,30,31,30,31,31,30,31,30,31};//闰年时候每月天数,角标0的数值为0这样可以以角标直接对应月份
- int[] common={0,31,28,31,30,31,30,31,31,30,31,30,31};//平年时每月天数
- for(int x=1989; x<=year; x++)
- if(x%4==0 && x%4!=0 ||x%400==0)
- count++;
- yearD=366*count+365*(year-1989-count);
-
- System.out.println(year+"年距1989年"+yearD+"天");
-
- if(year%4==0 && year%4!=0 ||year%400==0)
- {
- for(int x = 0; x<month; x++)
- monthD = monthD + leap[x];
- }
- else
- {
- for(int y = 0; y<month; y++)
- monthD = monthD + common[y];
- }
-
- monthD =monthD + yearD;
- System.out.println(year+"年"+month+"月距离1989年1月1日"+monthD+"天");
- }
- }
复制代码 |