package Lx;
/**
- 31 days: 1,3,5,7,8,10,12
- Day 30: 2.4.6.9,11
- February: Formula for determining leap years ()% 40&&年%100!=0&||年%4000
-
平年:28天
-
闰年:29天
- */
import java.time.Year;
import java.util.Scanner;
{class IFTest public
public static void main (String [] args) {
Scanner Scanner new new Key = (the System.in);
System.out.println ( "Please enter the year:");
// year year
int year = key.nextInt ();
System.out.println ( "Please enter the month:");
// month The month
int month = key.nextInt ();
/* if (month==1||month==3||month==5||month==7||month==8||month==10||month==12){
System.out.println(year+"年"+month+"月"+"这个月是31天");
}else if (month==4||month==6||month==9||month==11){
System.out.println(year+"年"+month+"月"+"这个月是30天");
}else if (month==2){
if( year%4==0&&year%100!=0||year%400==0){
System.out.println(year+"年"+month+"月"+"这个月是29天");
}else {
System.out.println(year+"年"+month+"月"+"这个月是28天");
}
}else {
System.out.println("请输入正确的月份");
}*/
//优化方法days天数
int days = 0;
if (month==1||month==3||month==5||month==7||month==8||month==10||month==12){
days = 31;
}else if (month==4||month==6||month==9||month==11){
days = 30;
}else if (month==2){
if( year%4==0&&year%100!=0||year%400==0){
days = 29;
}else {
days = 28;
}
}else {
System.out.println("请输入正确的月份");
}
System.out.println(year+"年"+month+"月"+"这个月有"+days+"天");
key.close();
}
}