Printing Perpetual calendar based on Java and printing Perpetual calendar with java

Source: Internet
Author: User

Printing Perpetual calendar based on Java and printing Perpetual calendar with java

Today's blog, the first blog post, about the Basic Java content, has a limited level. I am sorry, but I hope to make progress together with you on the way to programming.

 

Question: Enter the year and month to print the calendar of the corresponding year and month.

Example:

-------------------------------------------------------------------------------

Bytes ------------------------------------------------------------------------------------------------------------------

 

Problem Analysis:

1. First of all, 1970 was the time when the Unix system was born. In 1970, it became the first year of Unix, and in January 1, 1970, it was Thursday. Now, the calendar functions of most mobile phones can only be displayed on the day of January 1, 1970;

2. to print the calendar of a month of a year, first calculate the day of the week in January?

What is the day of the week when the first day is solved?

2.1: calculate the number of days of the year, that is, the number of days of the year ending in January 1, January 1. The for loop is used. Starting from January 1, 1970, the leap year is + 366, and the year is + 365;

2.2: calculate the number of days of the month, that is, the number of days as of January 1, 1st day of this month. Use the for loop to calculate the number of days of the month starting from January 1, January;

2.1.1: the leap year and switch are used to determine the number of days returned by the month;

2.3: calculate the total number of days from January 1, and the total number of days from January 1;

3. determine the total number of days of the month (the switch statement is used );

4. Print the calendar;

Code implementation:

A function prints PrintTitle (); that is, a fixed header is implemented;

Print (parameter 1, parameter 2, parameter 3); that is, Print the calendar subject;

Parameter 1 (total number of days): calculates the number of days per year and the number of days per month;

Parameter 2 is used to pass the year;

Parameter 3 is used to pass the month;

Sets an independent function for determining the leap year;

Summary:

Before solving the problem, you must analyze the problem, divide the big problem into small problems, clarify the logic, and implement the small problem logic. The entire problem has been achieved by 80%;

Bottom-up, step-by-step implementation, independent function calls;

Code implementation:

Bytes ------------------------------------------------------------------------------------------------------

Bytes -----------------------------------------------------------------------------------------------

Bytes ------------------------------------------------------------------------------------------------------

Bytes --------------------------------------------------------------------------------------------------

Bytes ------------------------------------------------------------------------------------------------------

Bytes ------------------------------------------------------------------------------------------------------

 

 

 

 

Bytes ------------------------------------------------------------------------------------------------------

 

Bytes ------------------------------------------------------------------------------------------------------

 

 

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.