📄 exercise3_33.java
字号:
// Exercise3_33.javaimport javax.swing.*;public class Exercise3_33 { public static void main(String[] args) { // Prompt the user to enter input String yearString = JOptionPane.showInputDialog("Enter a year:"); int year = Integer.parseInt(yearString); String firstDayString = JOptionPane.showInputDialog("Enter the first day of the year:"); int firstDay = Integer.parseInt(firstDayString); int numberOfDaysInMonth = 0; // Display calendar for each month for (int month = 1; month <= 12; month++) { // Display Calendar title switch (month) { case 1: System.out.print("January 1, " + year + " is "); numberOfDaysInMonth = 31; break; case 2: System.out.print("Feburary 1, " + year + " is "); if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) numberOfDaysInMonth = 29; else numberOfDaysInMonth = 28; break; case 3: System.out.print("March 1, " + year + " is "); numberOfDaysInMonth = 31; break; case 4: System.out.print("April 1, " + year + " is "); numberOfDaysInMonth = 30; break; case 5: System.out.print("May 1, " + year + " is "); numberOfDaysInMonth = 31; break; case 6: System.out.print("June 1, " + year + " is "); numberOfDaysInMonth = 30; break; case 7: System.out.print("July 1, " + year + " is "); numberOfDaysInMonth = 31; break; case 8: System.out.print("August 1, " + year + " is "); numberOfDaysInMonth = 31; break; case 9: System.out.print("September 1, " + year + " is "); numberOfDaysInMonth = 30; break; case 10: System.out.print("October 1, " + year + " is "); numberOfDaysInMonth = 31; break; case 11: System.out.print("November 1, " + year + " is "); numberOfDaysInMonth = 30; break; case 12: System.out.print("December 1, " + year + " is "); numberOfDaysInMonth = 31; break; } switch (firstDay) { case 0: System.out.println("Sunday"); break; case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesday"); break; case 4: System.out.println("Thursday"); break; case 5: System.out.println("Friday"); break; case 6: System.out.println("Saturday"); break; } // Get the start day for the next month firstDay = (firstDay + numberOfDaysInMonth) % 7; } System.exit(0); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -