Java outputs calendar codes for specified years and months based on the Calendar class.
This article shows you Java based on the Calendar class output calendar code for the specified year and month how to write, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
The code is as follows
Package com.cyl.test3; import java.util.Calendar;import java.util.Scanner; public class RiLi {public static void main (String [] args) {int year= 2020; int month= 2; Calendar calendar = Calendar.getInstance (); / / since the month in Java starts counting from October, the real month December (month=12) needs to be subtracted by 1 to be December calendar.set (year,month-1,1) in Java; / / the first day of each month int weekday = calendar.get (Calendar.DAY_OF_WEEK)-1 System.out.println ("the first day of the month" + weekday); int maxDay = calendar.getActualMaximum (Calendar.DAY_OF_MONTH); System.out.println ("maximum days of the month" + maxDay); System.out.println ("\ t\ t" + year+ "year" + month+ "month"); System.out.println ("1\ t 2\ t 3\ t 4\ t 5\ t 6\ t day\ t"); int temp = 0; / / fill in the blanks for (int I = 0; I < weekday-1 For +) {System.out.print ("\ t"); temp++;} for (int I = 1; I