牛客——华为笔试合集之HJ73
计算日期到天数转换
http://www.nowcoder.com/questionTerminal/769d45d455fe40b385ba32f97e7bcded
import java.util.Scanner;
public class Main {
public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String[] s = sc.nextLine().split(" "); int year = Integer.valueOf(s[0]); int month = Integer.valueOf(s[1]); int day = Integer.valueOf(s[2]); int Feb = 28; if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { //判断闰年 Feb = 29; } int[] arr = {31,Feb,31,30,31,30,31,31,30,31,30,31}; int sumDay = 0; for (int i = 0; i < month - 1; i++) { sumDay += arr[i]; } sumDay += day; System.out.println(sumDay); } sc.close(); }
}