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.