日历
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | public class runnian { public static void main(String[] arge, int sun) { System.out.println( "请输入年份" ); Scanner in = new Scanner(System.in); int year = in.nextInt(); if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ) { System.out.println( "闰年" ); } else { System.out.println( "平年" ); } System.out.println( "请输入月份" ); int month = in.nextInt(); switch (month) { case 2 : { if ((year % 4 ) == 0 ) { System.out.println(month + "月是28天" ); } else System.out.println(month + "月是29天" ); } break ; case 1 : break ; case 3 : break ; case 5 : break ; case 7 : break ; case 8 : break ; case 10 : break ; case 12 : System.out.println(month + "月是31天" ); break ; default : System.out.println(month + "月是30天" ); break ; } int sum = 0 ; int weekday = sum % 7 ; for ( int i = 1900 ; i < year; i++) { if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ) { sum += 366 ; } else { sum += 365 ; } } for ( int i= 1 ;i<month;i++){ if (i== 2 ){ if (year% 4 == 0 &&year% 100 != 0 ||year% 400 == 0 ){ sum+= 29 ; } else { sum+= 28 ; } } else { if (year% 4 == 0 &&year% 100 != 0 ||year% 400 == 0 ){ sum+= 30 ; } else { sum += 30 ; } } } int days= 0 ; if (month== 2 ){ if (year% 4 == 0 &&year% 100 != 0 ||year% 400 == 0 ){ days= 29 ; } else { days= 28 ; } } else if (month== 4 ||month== 6 ||month== 9 ||month== 11 ){ days= 30 ; } else { days= 31 ; } int weekdays=sum% 7 ; System.out.println( "日\t一\t二\t三\t四\t五\t六" ); for ( int i= 1 ;i<=weekdays;i++){ System.out.print( "\t" ); } for ( int i= 1 ;i<=weekday;i++){ if (sum% 7 == 6 ){ System.out.print(i+ "\n" ); } else { System.out.print(i+ "\n" ); } sum+= 1 ; } } } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步