LanQiaoTestCodes/星期几.java

47 lines
1.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package LanQiaoOJ;
/*题目描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
1949 年的国庆节( 10 月 1 日)是星期六。
今年2012的国庆节是星期一。
那么,从建国到现在,有几次国庆节正好是星期日呢?
不要求写出具体是哪些年,只要一个数目!*/
public class 星期几 {
//每月天数下标从1开始
static int [] w= {0,31,28,31,30,31,30,31,31,30,31,30,31};
//年月日星期
//t=0表示星期天t=1表示星期一
static int y=1949,m=10,d=1,t=6;
public static void main(String[] args) {
int count=0;
//循环结束条件
while(y!=2012||m!=10||d!=1) {
//判断是否闰年——>判断2月天数
if(y%400==0||y/400==0&&y/100!=0)
w[2]=29;
else
w[2]=28;
//判断是否完全平方
if(check())
count++;
//日期变更
d++;
//
t++;
t%=7;
if(d>w[m]) {
m++;
d=1;
}
if(m>12) {
y++;
m=1;
}
}
System.out.print(count);
}
static boolean check() {
return m==10&&d==1&&t==0;
}
}