Perpetual calendar (Java implementation)

Source: Internet
Author: User

Design Ideas :

The distance from the first day of the one months to the date entered was calculated on January 1, 1900 (the Year of January 1 for Monday) Totalday, (for example: Input 2015 6 6) calculated from 1900 1.1 to 2015 6.1;

With Totalday 7 + 1, you can get the input date that the first day of the one months is a few weeks, and then judge the number of days of the month output on the line.

1, 3, 5, 7, 8, 10, December 31 days, February leap years 29 days, common year 28 days, the remaining months 30 days;

Year is a multiple of 4 but not a multiple of 100, or the year is a multiple of 400;


Import java.util.*;p ublic class calendar{public static void Main (string[] args) {System.out.println ("Please enter Date"); Scanner in=new Scanner (system.in); int year=in.nextint (); int month=in.nextint (); int days=in.nextint (); int cnt=0;// Calculates the year difference, the cumulative date (from January 1, 1900) (January 1, 1900 is Monday) for (int i=1900;i<year;i++) {if (i%4==0&&i%100!=0| | i%400==0) cnt+=366;elsecnt+=365;} int cnt2=0;//calculates the date of the cumulative monthly difference for (int i=1;i<month;i++) {if (i==2) {if (year%4==0&&year%100!=0| | year%400==0) cnt2+=29;elsecnt2+=28;} else if (i==4| | i==6| | i==9| | i==11) Cnt2+=30;else cnt2+=31;} int totalday=cnt+cnt2+1;//The first day of the month that entered the date with the date of January 1, 1900//system.out.println (totalday); int monweek= (TOTALDAY%7); The first day of the month in which the input date is judged is//system.out.println (Monweek); System.out.println ("t \ t two \ t three \ Four \ five \ t six"); int limit;//There are days if (month==2) {if (year%4==0&&year%100!=0| | year%400==0) limit=29;elselimit=28;} else if (month==4| | month==6| | month==9| | month==11) limit=30;elselimit=31;int k=1;for (int i=0;i<monweek;i++) System.out.print ("\ T"), while (k!=limit+1) { System.out.Print (k++ + "\ t"); Monweek++;if (monweek%7==0) System.out.println ();} System.out.println ();}}


Perpetual calendar (Java implementation)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.