题解 | #计算日期到天数转换#判断是否闰年,累加天数
计算日期到天数转换
http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int year=sc.nextInt();
int month=sc.nextInt();
int day=sc.nextInt();
int[] arr=new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
int days=0;
for(int i=0;i<month-1;i++){
days+=arr[i];
}
if(isRun(year) && month>2){
days+=1;
}
days+=day;
System.out.println(days);
}
public static boolean isRun(int year){
return year%400==0 || (year%4==0 && year%100!=0);
}
}