Today just opened the blog, the first blog post, an article on the basic Java content, the level of limited, many forgive me, hope and everyone in the learning program on the road to common progress.
Question: Enter the year, month, and date to print the calendar.
Example:
-------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- ---
Problem Analysis:
1, the first 1970 is the UNIX system but the time, 1970 became UNIX, January 1, 1970 is Thursday, now most of the phone's calendar function can only be displayed to January 1, 1970 this day;
2, if you want to print a calendar of a certain month, you should first calculate the number of days of the month 1th is the day of the week?
What's the day of the week for solving number 1th?
2.1: First calculate the number of days, that is, the number of days until January 1, 1, with a for loop, starting from 1970, leap year +366, common year +365;
2.2: Calculate moon days, that is, the number of days as of the month 1th, with for loop, starting from January, calculate moon days;
2.1.1: Use a leap year to judge, use switch to determine the number of months to return;
2.3: Use the number of days plus months, the month to obtain the number of 1th days from January 1, 1970, the total number of days to determine the month 1th is the day of the week;
3, determine the total number of days this month (using the switch statement);
4: Print the calendar;
Code implementation:
A function is implemented to print printtitle (), i.e. to implement a fixed head part;
Implementation of print (parameter 1, parameter 2, Parameter 3), that is, the realization of the printed calendar theme section;
Parameter 1 (total days calculated): Calculates the number of days of the year, calculates the number of months;
Parameter 2 passing year;
Parameter 3 passes the month;
Judge the leap year set independent function;
Summarize:
Before solving the problem, we must first analyze the problem, divide the big problems into small problems, clarify the logic, realize the logic of small problems, the whole problem has been achieved 80%;
Bottom-up, progressive implementation, function-independent invocation;
Code Implementation section:
------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
Print perpetual calendar of Java basics