Question: Write a program that, given a month and year, prints a calendar, such as June 2016 Su Mo Tu We Th Fr Sa 1 2
Write a program that, given a month and year, prints a calendar, such as
June 2016 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
To find out the weekday of the first day of the month, call:
int weekday = java.time.LocalDate.of(year, month, 1).getDayOfWeek().getValue();
// 1 = Monday, 2 = Tuesday, ..., 7 = Sunday To find out how many days in a month call the following including handling leap-year months, e.g. 2/29/2020, which will return 29:
LocalDate date = LocalDate.of(year, month, day); int lengthOfMonth = date.lengthOfMonth();
You will need to fully qualify LocalDate or use an import statement to import the class or its package, e.g. import java.time.LocalDate or import java.time.*;
IntelliJ will allow you to add imports by using Alt-Enter on the unresolved class name error, thereby resolving the error for you in most cases.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
