🎯解题思路
1.首先 ,要先判断给出的年份是否为润年,且给出的月份mounth>2; 2.然后将mounth-1个月的天数加上day;
🎯完整代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int year = scanner.nextInt();
int mounth = scanner.nextInt();
int day = scanner.nextInt();
int[] mounth_day = {31,28,31,30,31,30,31,31,30,31,30,31};
int days = 0;
for (int i = 0; i < mounth-1; i++) {
days+=mounth_day[i];
}
if(is_deapyear(year) && mounth>2){
days+=day+1;
} else {
days+=day;
}
System.out.println(days);
}
private static boolean is_deapyear(int year) {
return (year % 400 ==0) || ((year % 4== 0) && (year%100!=0));
}
}