首先要清楚月份天数的分类
每年的4,6,9,11月的天数都是30天
每年的1,3,5,7,8,10,12月都是31天
然后计算2月的天数
2月的天数有两种,闰年为29天,非闰年28天
判断是否为闰年的标准:
(四年一闰&&百年不闰)||四百年一闰
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
String s = scan.nextLine();
String[] sa = s.split(" ");
int year = Integer.parseInt(sa[0]);
int month = Integer.parseInt(sa[1]);
int days = 31;
if(month==4||month==6||month==9||month==11){
System.out.println(30);
}
else if(month==2){
//判断是否为闰年
if((year%4==0&&year%100!=0)||year%400==0){
System.out.println(29);
}
else{
System.out.println(28);
}
}
else
System.out.println(31);
}
}
}
京公网安备 11010502036488号