public static void main(String[] args) {
// 根据用户输入的年月日 计算出该日期是该年的第几天并输出结果。
//公历:分为平年和闰年
//平年31天月份:1 ,3,5,7,8, 10, 12 ;2月28天,4,6,9,11月份30天
//平年每月的天数
int [] arr = {31,28,31,30,31,30,31,31,30,31,30,31};
//闰年天数? 只是2月多了一天
Scanner s = new Scanner(System.in);
System.out.println("请分别输入年月日:");
int year =s.nextInt();
int month =s.nextInt();
int day =s.nextInt();
int sumMonthDays =0;
//计算本月之前的天数和
for(int i=0;i<month-1;i++){
sumMonthDays+=arr[i];
}
/*普通闰年:公历年份是4的倍数的,且不是100的倍数,为闰年。(如2004年就是闰年);
世纪闰年:公历年份是整百数的,必须是400的倍数才是闰年(如1900年不是世纪闰年,2000年是世纪闰年);*/
if(((year%4==0 && year%100!=0) || year%400==0) && month>2){
int sumDays =sumMonthDays+day+1;
System.out.println(year+"年"+month+"月"+day+"日是"+year+"年的第"+sumDays+"天");
}else{
int sumDays =sumMonthDays+day;
System.out.println(year+"年"+month+"月"+day+"日是"+year+"年的第"+sumDays+"天");
}
}