java 20008年月历输出 日期的个位与星期数相等 的日子

/*
 * 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);
    }
}


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值