1. 题目
读题
考查点
2. 解法
思路
需要先了解闰年以及日历相关的知识
代码逻辑
具体实现
public class HJ073 {
public static int[] dayNum = {1, -2, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
int month = sc.nextInt();
int day = sc.nextInt();
System.out.println(getDaySeq(year, month, day));
}
public static int getDaySeq(int year, int month, int day) {
int offset = 0;
for (int i = 0; i < month - 1; i++) {
offset += dayNum[i];
}
int seq = 30 * (month - 1) + offset + day;
if (month > 2 && (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)) {
seq++;
}
return seq;
}
}