"Common" Java perpetual calendar code

Source: Internet
Author: User

1 Package Com.bdqn.test1;2 3 import Java.util.Scanner;4 5  Public classWannianli {6     7Scanner input =NewScanner (System.inch);8     intyear;//year9     intMonth//MonthTen     intDays = to;//The default is 31 days, so when judging directly except 4,6,9,11,2, One      A     /* - * Show Menu -      */ the      Public voidmenu () { -System. out. println ("Please enter the year"); -Year =input.nextint (); -System. out. println ("Please enter the month"); +month =input.nextint (); -          +         Switch(month) { A              Case 4: at              Case 6: -              Case 9: -              Case  One: -Days = -; -                  Break; -              Case 2: in                 //If the year can be divisible by 4 but not divisible by 100 + years by 400 . -                 if(Year%4==0&& Year% -!=0|| Year% -==0) { toDays = in; +                      Break; -}Else { theDays = -; *                 } $                  Break;Panax Notoginseng             default: -Days = to; the         } + Show (); A     } the      +      Public voidShow () { -         //1900-1-1 Monday 1900-1-9 (stipulated) $String[] weeks = {"Day","a","two","three","Four","Five","Six" }; $          for(inti =0; i < weeks.length; i++) { -System. out. print (Weeks[i] +"\ t"); -         } theSystem. out. println ("\n=================================="); -         intChadays =0;Wuyi          for(inti =1900; i < year; i++) { the             ifI4==0&& I% -!=0|| I -==0) { -Chadays + =366;//leap year 366 days Wu                 Continue; -             } AboutChadays + =365; $         } -         //The above method calculates the year from January 1, 1900 to the input, and the following method adds the input month to the -         //last for Chadays, the following for loop continues to accumulate on chadays -         //note here that the For loop is the summation of each month A          for(inti =1; I < month; i++) { +             Switch(i) { the              Case 1: -              Case 3: $              Case 5: the              Case 7: the              Case 8: the              Case Ten: the              Case  A: -Chadays + = to; in                  Break; the              Case 4: the              Case 6: About              Case 9: the              Case  One: theChadays + = -; the                  Break; +              Case 2: -                 //If the year can be divisible by 4 but not divisible by 100 + years by 400 . the                 if(Year%4==0&& Year% -!=0|| Year% -==0) {BayiChadays + = in; the}Else { theChadays + = -; -                 } -                  Break; the             } the         } the          the          - //System.out.println ("Days of Difference:" + chadays); the          the         intWeekofday = (Chadays +1) %7;//the reason for the addition is that the first in the Sunday array the //System.out.println (weekofday);94          for(inti =0; i < Weekofday; i++) { theSystem. out. Print ("\ t");//Space-Fill the         } the          for(inti =1; I <= days; i++) {98System. out. print (i +"\ t"); About             if((i + weekofday)%7==0) {//seven on each line, just a break. -System. out. println ();101             }102         }103     104     } the      Public Static voidMain (string[] args) {106         107Wannianli wnianli=NewWannianli ();108 Wnianli.menu ();109          the         111     } the}

"Common" Java perpetual calendar code

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.