/**
* 输入某年某月某日,判断这一天是这一年的第几天?
*/
System.out.print("请输入年、月、日:");
int year=inp.nextInt();//年份
int month=inp.nextInt();//月份
int day=inp.nextInt();//天
int dayCount=0;
int bigMonth=31,smallMonth=30,miniMonth=28;
/**
* 判断是否为闰年
*/
boolean isTrue=false;
if((year%4==0&&year%100!=0)||(year%400==0)){
isTrue=true;
miniMonth=29;
}
switch (month) {
case 1:
dayCount=day;
break;
case 2:
dayCount=bigMonth+day;
break;
case 3:
dayCount=miniMonth+2*bigMonth;
break;
case 4:
dayCount=miniMonth+2*bigMonth+smallMonth;
break;
case 5:
dayCount=miniMonth+3*bigMonth+smallMonth;
break;
case 6:
dayCount=miniMonth+3*bigMonth+2*smallMonth;
break;
case 7:
dayCount=miniMonth+4*bigMonth+2*smallMonth;
break;
case 8:
dayCount=miniMonth+5*bigMonth+2*smallMonth;
break;
case 9:
dayCount=miniMonth+5*bigMonth+3*smallMonth;
break;
case 10:
dayCount=miniMonth+6*bigMonth+3*smallMonth;
break;
case 11:
dayCount=miniMonth+6*bigMonth+4*smallMonth;
break;
case 12:
dayCount=miniMonth+7*bigMonth+4*smallMonth;
break;
default:
break;
}
System.out.println(year+"年"+month+"月"+day+"日是该年的第"+dayCount+"天");
* 输入某年某月某日,判断这一天是这一年的第几天?
*/
System.out.print("请输入年、月、日:");
int year=inp.nextInt();//年份
int month=inp.nextInt();//月份
int day=inp.nextInt();//天
int dayCount=0;
int bigMonth=31,smallMonth=30,miniMonth=28;
/**
* 判断是否为闰年
*/
boolean isTrue=false;
if((year%4==0&&year%100!=0)||(year%400==0)){
isTrue=true;
miniMonth=29;
}
switch (month) {
case 1:
dayCount=day;
break;
case 2:
dayCount=bigMonth+day;
break;
case 3:
dayCount=miniMonth+2*bigMonth;
break;
case 4:
dayCount=miniMonth+2*bigMonth+smallMonth;
break;
case 5:
dayCount=miniMonth+3*bigMonth+smallMonth;
break;
case 6:
dayCount=miniMonth+3*bigMonth+2*smallMonth;
break;
case 7:
dayCount=miniMonth+4*bigMonth+2*smallMonth;
break;
case 8:
dayCount=miniMonth+5*bigMonth+2*smallMonth;
break;
case 9:
dayCount=miniMonth+5*bigMonth+3*smallMonth;
break;
case 10:
dayCount=miniMonth+6*bigMonth+3*smallMonth;
break;
case 11:
dayCount=miniMonth+6*bigMonth+4*smallMonth;
break;
case 12:
dayCount=miniMonth+7*bigMonth+4*smallMonth;
break;
default:
break;
}
System.out.println(year+"年"+month+"月"+day+"日是该年的第"+dayCount+"天");