10,000 calendar: enter a year, then enter another month, print out the calendar of that month that month
(January 1, 1900 is Monday).
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter the year:");
int year = scanner.nextInt();
System.out.println("Please enter the month:");
int month = scanner.nextInt();
int allDayOfYear = 0;// records between the days between 1900 and entering the year
int allDayOfMonth = 0;// Number of days from January 1 to the input month
int day = 0;// Record Entering the month of the month
for(int i=1900;i<year;i++){
if(i%4==0&&i%100!=0 || i%400==0){
// true means that the year was a leap year
allDayOfYear +=366;
}else{
allDayOfYear +=365;
}
}
for (int i=1;i<month;i++) {
switch (i) {
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
allDayOfMonth += 31;
break;
case 4: case 6: case 9: case 11:
allDayOfMonth += 30;
break;
case 2:
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
allDayOfMonth += 29;
} else {
allDayOfMonth += 28;
}
break;
}
}
int allDay = allDayOfYear + allDayOfMonth + 1;//1900.1.1 to the total number of days on the first day of the input month
int week = allDay % 7 ;// The first day of the month of the input month is the week of the week
System.out.println("The first day of the month is week"
13 years -" + week);
switch(month){
case 1:case 3:case 5:case 7:case 8:case 10:case 12:
day = 31;
break;
case 4:case 6:case 9:case 11:
day = 30;
break;
case 2:
if(year%4==0&&year%100!=0 || year%400==0){
day = 29;
}else{
day = 28;
}
break;
}
System.out.println("----" + year + + month + "Month");
System.out.println("One \ t two \ t three \ t four \ t five \ t six \ t days");
int num = 0;// Control printing and replacement
for (int i=1;i<week;i++){
System.out.print("\t");
num++;
}
for (int i=1;i<=day;i++){
System.out.print(i + "\t");
num++;
if(num%7==0) {
System.out.println();
}
}
}
}