/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
* 20008年月历输出 日期的个位与星期数相等 的日子 并统计天数 (个位数为0当作周日)
*上一个版本有错,只是修改过的,大家可以用万年历查一下结果。
*/
package pkg08date;
/**
*
* @author Administrator
*/
class printweek {
public String print(int w) {
String b = null;
switch (w) {
case 1:
b = "星期一";
break;
case 2:
b = "星期二";
break;
case 3:
b = "星期三";
break;
case 4:
b = "星期四";
break;
case 5:
b = "星期五";
break;
case 6:
b = "星期六";
break;
case 0:
b = "星期日";
break;
}
return b;
}
}
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int y = 2008;
int days = 0, m, week, d, c, count = 0;
printweek p = new printweek();
for (m = 1; m < 13; m++) {
switch (m) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
for (d = 1; d < 32; d++) {
days++;
week = ((y - 1) + (int) (y - 1) / 4 - (int) (y - 1) / 100 + (int) (y - 1) / 400 + days) % 7;
c = d % 10;
if (c == week) {
System.out.println("2008年" + m + "月" + d + "日恰好是" + p.print(week));
count++;
}
}
break;
case 4:
case 6:
case 9:
case 11:
for (d = 1; d < 31; d++) {
days++;
week = ((y - 1) + (int) (y - 1) / 4 - (int) (y - 1) / 100 + (int) (y - 1) / 400 + days) % 7;
c = d % 10;
if (c == week) {
System.out.println("2008年" + m + "月" + d + "日恰好是" + p.print(week));
count++;
}
}
break;
case 2:
for (d = 1; d < 30; d++) {
days++;
week = ((y - 1) + (int) (y - 1) / 4 - (int) (y - 1) / 100 + (int) (y - 1) / 400 + days) % 7;
c = d % 10;
if (c == week) {
System.out.println("2008年" + m + "月" + d + "日恰好是" + p.print(week));
count++;
}
}
break;
}
}
System.out.println("2008年日期的个位数与相应的星期恰好相同的总天数为:" + count);
}
}