Java basics of printing a simple implementation of the calendar (case) _java

Source: Internet
Author: User

Question: Enter the year, month, and print the corresponding calendar.

Example:

Problem Analysis:

1, first 1970 is the birth of Unix system time, 1970 became the year of Unix, January 1, 1970 is Thursday, now most of the mobile phone calendar features can only be displayed to January 1, 1970 this day;

2, to print the calendar of a certain month, you should first calculate the month 1th is the day of the week?

What's the day of the week, number 1th?

2.1: First calculate the number of years, that is, the number of days up to January 1, 1, with a for loop, starting from 1970, leap year +366, excepting +365;

2.2: Calculate moon days, that is, the number of days up to 1th this month, with a for loop, starting from January, Count moon days;

2.1.1: Use leap year to judge, use switch to judge return month days;

2.3: The number of days plus months, to obtain this month, 1th distance from January 1, 1970 of the total number of days, the total number of days to determine the number of this month 1th is the week;

3, to determine the total number of days this month (using the switch statement);

4, print the calendar;

Code implementation:

A function realizes the print printtitle (), namely realizes the fixed head part;

Implement print (parameter 1, parameter 2, parameter 3);

Parameter 1 (Calculate total days): Calculate the number of days, calculate the number of days;

Parameter 2 transmission year;

Parameter 3 passing month;

Judge Leap year set independent function;

Summarize:

Before solving the problem, we must first analyze the problem, divide the big problem into small problem gradually, clear logic and realize the logic of small problem, the whole problem has already realized 80%;

bottom-up, step-by-step implementation, function independent call;

Code Implementation section:

-

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

----

--------

--------

--------

--------

The above Java basic Print calendar of the simple implementation (case) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

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.