public static void main(String[] args) { boolean flag=true; while(flag){ Scanner sc=new Scanner(System.in); System.out.println("请输入年份"); int year=sc.nextInt(); System.out.println("请输入月份"); int month=sc.nextInt(); //当前月的天数 int currentDay=0; //闰年计数 int count=0; if(year<1900){ System.out.println("您输入的年份不符合要求,请输入大于1900的年份"); continue; } for(int i=1900;i<year;i++){ if((i%4==0&&i%100!=0)||i%400==0){ count++; } } int preYear=(year-1900)*365+count; int totalMonthDay=0; for(int i=1;i<=month;i++){ int days=0; switch (i) { case 2: { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { days = 29; } else { days = 28; } break; } case 4: case 6: case 9: case 11: { days = 30; break; } default: days = 31; break; } if(i==month){//当前月的天数 currentDay=days; } totalMonthDay+=days; } int week=(preYear+totalMonthDay-currentDay+1)%7; System.out.println("星期天\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六"); int blank=0; //打印日期前空格 for(int i=1;i<=week;i++){ blank++; System.out.print("\t"); } //打印日期 for(int i=1;i<=currentDay;i++){ if(blank%7==0){ System.out.println(); } blank++; System.out.print(i+"\t"); } String l=sc.next(); System.out.println("继续按Y"); if(l.equalsIgnoreCase("l")){ continue; } else{ System.out.println("退出系统"); break; } } }
添加回答
举报
0/150
提交
取消