【Java】运用泽勒一致性计算某天是星期几

 1 /**
 2  * Created by liangjiahao on 2017/2/26.
 3  * 运用泽勒一致性计算某天是星期几?
 4  * 公式:
 5  *          h = (q + 26(m+1)/10 + k +k/4 + j/4 +5j) % 7
 6  *                   
 7  */
 8 
 9 
10 import java.util.Scanner;
11 public class Zeller {
12     public static void main(String args[]){
13         Scanner imput = new Scanner(System.in);
14 
15         System.out.print("Enter a year: (e.g, 2012): ");
16         int year = imput.nextInt();
17 
18         System.out.print("Enter a mouth: 1-12:  ");
19         int mouth = imput.nextInt();
20 
21         System.out.print("Enter the day of the mouth: ");
22         int day = imput.nextInt();
23 
24         int tempMouth = mouth;      //一月二月记为13,14,年数记为上一年
25         switch (tempMouth){
26             case 1: mouth = 13; year -=1; break;
27             case 2: mouth = 14; year -=1; break;
28         }
29 
30         int century = year / 100;
31         int yearOfCentury = year % 100;
32         
33         int theDayIs = (day + 26 * (mouth + 1) / 10 + yearOfCentury + yearOfCentury / 4 + century / 4 + 5 * century) % 7;
34         //0为周六1为周日2为周一3为周二4为周三5为周四6为周五
35         switch (theDayIs){                                     
36             case 0 :System.out.println("Day of the week is Saturday"); break;
37             case 1 :System.out.println("Day of the week is Sunday"); break;
38             case 2 :System.out.println("Day of the week is Monday"); break;
39             case 3 :System.out.println("Day of the week is Tuesday"); break;
40             case 4 :System.out.println("Day of the week is Wednesday"); break;
41             case 5 :System.out.println("Day of the week is Thursday"); break;
42             case 6 :System.out.println("Day of the week is Friday"); break;
43         }
44 
45     }
46 }

 

转载于:https://www.cnblogs.com/liangjiahao713/p/6464130.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值