package test;
import java.util.Scanner;
public class zuoye {
public static void main(String[] args) {
Scanner n = new Scanner(System.in);
int year, month, day = 0;
int days;
int e = 0;// 用来进行判断的
int d = 0;// 累计天数
do {
System.out.println("输入年月日:");
year = n.nextInt();
month = n.nextInt();
days = n.nextInt();
if (year < 0 || month < 0 || month > 12 || days < 0 || days > 31) {
System.out.println("输入错误");
e = 1;// 等于1时,说明输入有误6
}
// 年月日大于0
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
if (days <= 31) {
break;
} else {
System.out.println("本月不超过31天");
e = 1;
}
}
// 1,3,5,7,8,10,12月份不超过31天
if (month == 4 || month == 6 || month == 9 || month == 11) {
if (days <= 30) {
break;
} else {
System.out.println("本月不超过30天");
e = 1;
}
}
// 4,6,9,11月份不超过30天
if (month == 2) {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
if (days > 29) {
System.out.println("闰年2月不超过29天");
e = 1;
} else {
e = 0;
}
}
// 闰年2月不超过29天
if (year % 4 != 0 || (year % 4 == 0 && year % 100 == 0)) {
if (days > 28) {
System.out.println("非闰年2月不超过28天");
e = 1;
} else {
e = 0;
}
}
// 非闰年2月不超过28天
}
} while (e == 1);// 判断等于1时,就继续输入
for (int i = 1; i < month; i++) {
switch (i) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day = 31;
break;
case 2:
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
day = 29;// 闰年2月有29天
} else {
day = 28;// 非闰年2月有28天
}
break;
case 4:
case 6:
case 9:
case 11:
day = 30;
break;
default:
System.out.println("输入的月份有误");
}
d += day;
}
System.out.println("这是" + year + "年的第" + (d + days) + "天");
}
}