牛客网真题2019-34-今年的第几天
今年的第几天
http://www.nowcoder.com/questionTerminal/cc6ad889f95c49c08da1b338dd2e07ab
闰年:(y % 4 == 0 && y % 100 != 0) || y % 400 == 0
package org.niuke.solution34;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int[] date = new int[]{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
while (sc.hasNext()) {
int y = sc.nextInt(), m = sc.nextInt(), d = sc.nextInt();
if((y % 4 == 0 && y % 100 != 0) || y % 400 == 0){
System.out.println(date[m - 1] + d + 1);
}else{
System.out.println(date[m - 1] + d);
}
}
}
}
查看4道真题和解析