51,411
社区成员
发帖
与我相关
我的任务
分享

public static void main(String[] args) {
String Date;
Scanner in = new Scanner(System.in);
System.out.println("请按照XXXX-XX-XX格式输入一个生日日期");
Date = in.next();
String[] Dates = Date.split("-");
try {
int year = Integer.parseInt(Dates[0]);
int month = Integer.parseInt(Dates[1]);
int day = Integer.parseInt(Dates[2]);
if ((year >= 1900) && (year <= 2013)) {
if ((month) >= 1 && (month <= 12)) {
if ((day >= 1) & (day <= 31)) {
System.out.println("您的生日格式正确");
} else {
System.out.println("日期格式不正确");
}
} else {
System.out.println("月份格式不正确");
}
}
} catch (Exception e) {
System.out.println("输入错误");
}
}