判断日期
原创
©著作权归作者所有:来自51CTO博客作者wx59c7233716b35的原创作品,请联系作者获取转载授权,否则将追究法律责任
输入某年某月某日,判断这一天是这一年中的第几天(注意闰年)
运行结果示例:
public static void main(String[] args){
int feb=28;
Scanner sc=new Scanner(System.in);
System.out.println("请输入年份");
int year=sc.nextInt();
System.out.println("请输入月");
int month=sc.nextInt();
System.out.println("请输入日");
int day=sc.nextInt();
if(year%4==0 && year%100!=0 || year%400==0){
feb=29;
}
int sum = 0;
switch(month){
case 1 : sum=day;
break;
case 2 : sum=31+day;
break;
case 3 : sum=31+feb+day;
break;
case 4 : sum=31+feb+31+day;
break;
case 5 : sum=31+feb+31+30+day;
break;
case 6 : sum=31+feb+31+30+31+day;
break;
case 7 : sum=31+feb+31+30+31+30+day;
break;
case 8 : sum=31+feb+31+30+31+30+31+day;
break;
case 9 : sum=31+feb+31+30+31+30+31+31+day;
break;
case 10 : sum=31+feb+31+30+31+30+31+31+30+day;
break;
case 11 : sum=31+feb+31+30+31+30+31+31+30+31+day;
break;
case 12 : sum=31+feb+31+30+31+30+31+31+30+31+30+day;
break;
}
System.out.println(year+"年 "+month+"月 " + day + "号是"+year+"年的第"+sum+"天");
}