Scanner scan = new Scanner(System.in);
System.out.println("请输入一个年份:");//向控制台输出一个提示信息
long year;
try{
year = scan.nextLong();
System.out.println("请输入一个月份:");
Long month=scan.nextLong();
if(year%4 == 0 && year%100!=0 || year%400 == 0){//是闰年
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){
System.out.print(year+"年"+month+"月有31天");
}else if(month==2){
System.out.print(year+"年"+month+"月有29天");
}else{
System.out.print(year+"年"+month+"月有30天");
}
}else{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){
System.out.print(year+"年"+month+"月有31天");
}else if(month==2){
System.out.print(year+"年"+month+"月有28天");
}else{
System.out.print(year+"年"+month+"月有30天");
}
}
}catch(Exception e){
System.out.println("输入年份错误");
}