public static void amam(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("请输入一个年份值:");
int year = scan.nextInt();
System.out.println("请输入一个月份值:");
int month = scan.nextInt();
//判断输入合法性
System.out.println("请输入一个天:");
int day = scan.nextInt();
//判断合法性
day--;
if(day < 1){
day = 31;
if(month == 5 || month == 7 || month == 10 || month == 12){
day = 30;
}else if(month == 3){
day = (year % 400 == 0 || (year % 4 == 0 && year % 100 !=0))?29:28;
}if(month == 1){
year--;
month = 12;
}else{
month--;
}
}
System.out.println(year+"年"+month+"月"+day+"日");
}
能解释下整个代码的意思吗?
尤其是这段:
if(month == 5 || month == 7 || month == 10 || month == 12)
Its_forever
相关分类