主要问题在于:
1.通过年份,判断是否为闰年;
2.通过月份,判断是否为31天;
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int year=scan.nextInt();
int month=scan.nextInt();
int day=scan.nextInt();
//准备map
Map<Integer,Integer> map=new HashMap<>();
for(int i=1;i<=12;i++){
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
map.put(i,31);
}else{
map.put(i,30);
}
}
//二月的天数的判断
if(year%4==0&&year%100!=0){
map.put(2,29);
}else if(year%100==0&&year%400==0){
map.put(2,29);
}else{
map.put(2,28);
}
int count=0;
//判断第几天
for(int i=1;i<month;i++){
count+=map.get(i);
}
count+=day;
//输出
System.out.println(count);
}
}