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)
1 回答
Its_forever
TA贡献361条经验 获得超328个赞
这段程序要干什么我不太清楚,但是这句话的意思是:if(month == 5 || month == 7 || month == 10 || month == 12)
当输入的月份为5,7,10,12(或者的关系)时,
设置day为30天。
添加回答
举报
0/150
提交
取消