public static void main(String[] args) {
System.out.println("请按照格式输入yyyy-MM-dd");
Scanner sc = new Scanner(System.in);
String text = sc.next();
int y, m, d, sum = 0;
String[] strings = text.split("-");
y = Integer.parseInt(strings[0]);
m = Integer.parseInt(strings[1]);
d = Integer.parseInt(strings[2]);
// 核心代码
for (int i = 1; i < m; i++) {
switch (i) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
sum += 31;
break;
case 4:
case 6:
case 9:
case 11:
sum += 30;
break;
case 2:
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) {
sum += 29;
} else {
sum += 28;
}
break;
}
}
sum += d;
System.out.println("你输入的" + text + "是今年第" + sum + "天");
}
具体细节我就不想说了,反正我觉得容易理解的,这或许是我c的记忆里尽剩下的一个