【Java】運用澤勒一致性計算某天是星期幾

來源:互聯網
上載者:User

標籤:color   sunday   span   enter   system   []   void   logs   bre   

 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 }

 

【Java】運用澤勒一致性計算某天是星期幾

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.