//输入月份和天数确定是某年的多少天
//不确定年份
int year = new Scanner(System.in).nextInt();
int month =new Scanner(System.in).nextInt();
int day =new Scanner(System.in).nextInt();
int sumDays = 0;
switch (month) {
case(12):sumDays+=30;
case(11):sumDays+=31;
case(10):sumDays+=30;
case(9):sumDays+=31;
case(8):sumDays+=31;
case(7):sumDays+=30;
case(6):sumDays+=31;
case(5):sumDays+=30;
case(4):sumDays+=31;
case(3):
if((year%100==0&&year%4!=0)||year%400==0) {//判断是否是闰年
sumDays+=29;
}else {sumDays+=28;}
case(2):sumDays+=31;
case(1):sumDays+=day;
System.out.println( year+"年的第"+sumDays+"天");
}
java输入年月日判断该年的第几天
最新推荐文章于 2024-08-22 20:20:47 发布