晚了这么久,好歹做出来了还是发一下- class Fri13
- {
- public static void main(String[] args)
- {
- int[] result=new int[7];
- int weekday;
- for (int year=1900;year<2300;year+=1)
- {
- int s1=365*(year-1900)-((year-1900)/4-1);
- for (int month=1;month<13;month+=1)
- {
- int s2=0;
- if (year%4==0)
- {
- int[] monthday={0,31,29,31,30,31,30,31,31,30,31,30,31};
- for (int i=0;i<month-1;i+=1)
- s2+=monthday[i];
- }
- else
- {
- int[] monthday={0,31,28,31,30,31,30,31,31,30,31,30,31};
- for (int i=0;i<month-1;i+=1)
- s2+=monthday[i];
- }
- weekday=(s1+s2+13)%7;
- result[weekday]+=1;
- }
- }
- System.out.println("从1900到2300年,13号落在每个星期数上的次数:");
- System.out.println("星期日"+"\t"+"星期一"+"\t"+"星期二"+"\t"+"星期三"+"\t"+"星期四"+"\t"+"星期五"+"\t"+"星期六");
- System.out.println(result[0]+"\t"+result[1]+"\t"+result[2]+"\t"+result[3]+"\t"+result[4]+"\t"+result[5]+"\t"+result[6]);
- }
- }
复制代码 |