"*/import java.util.Scanner;// 用来存储被选中的日期class Date { private int year; private int month; private int day; // 构造器 public Date(int year, int month, int day) { this.year = year; this. month = month; this.day = day; } // 判断输入的日期是否合法 public boolean isAValidDate() { boolean flag = false; if (month > 0 && month < 13) { switch (month) { case 2: // 2月份有两种天数(闰年和非闰年) if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { if (day > 0 && day < 30) { flag = true; } } else { if (day > 0 && day < 29) { flag = true; } } break; case 4: // 4、6、9、11月份只有30天 case 6: case 9: case 11: if (day > 0 && day < 31) { flag = true; } break; default: // 其他月份含31天 if (day > 0 && day < 32) { flag = true; } break; } } return flag; } // 当输入的日期合法,根据用户的选择生成日期 public String generateNextDate(int choose) { switch (choose) { case 1: // 将日期往后一天推算 if (day == 31 && month == 12) { year = year 1; month = 1; day = 1; } else if (day == 31 && (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10)) { month = month 1; day = 1; } else if (day == 30 && (month == 4 || month == 6 || month == 9 || month == 11)) { month = month 1; day = 1; } else if ((day == 28 && month == 2 && year % 4 == 0 && year % 100 !=0 || year % 400 == 0)) { month = 2; day = 29; } else if (day == 28 && month == 2) { month = 3; day = 1; } else { day = day 1; } break; case 2: // 将日期往前推算一天 if (day == 1 && month == 1) { year = year - 1; month = 12; day = 31; } else if (day == 1 && (month == 2 || month == 4 || month == 6 || month == 8 || month == 9 || month == 11 || month == 1)) { month = month - 1; day = 31; } else if (day == 1 && (month == 5 || month == 7 || month == 10 || month == 12)) { month = month - 1; day = 30; } else if (day == 1 && month == 3 && year % 4 == 0 && year % 100 !=0 || year % 400 == 0) { month = 2; day = 29; } else if (day == 1 && month == 3) { month = 2; day = 28; } else { day = day - 1; } break; default: // 默认返回该日期 break; } return " " year "年" month "月" day "日"; }}public class date { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("请输入一个日期(年、月、日):"); int year = in