python输入年份月份输出天数_输入年份月份输出对应的天数
Posted weixin_39715187
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python输入年份月份输出天数_输入年份月份输出对应的天数相关的知识,希望对你有一定的参考价值。
方法1.
//数据输入
Scanner scanner=new Scanner(System.in);
System.out.println("请输入年份(例如2012)");
int year=scanner.nextInt();
System.out.println("请输入月份");
int mounth=scanner.nextInt();
scanner.close();
//判断是不是闰年
boolean isrui=(year%4==0&&year%100!=0) || year%400==0;
//判断月份
if(isrui)
switch(mounth)
case 1:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 2:
System.out.println(year+"年"+mounth+"月有"+29+"天");
break;
case 3:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 4:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 5:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 6:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 7:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 8:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 9:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 10:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 11:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 12:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
else
switch(mounth)
case 1:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 2:
System.out.println(year+"年"+mounth+"月有"+28+"天");
break;
case 3:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 4:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 5:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 6:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 7:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 8:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 9:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 10:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 11:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 12:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
方法二.
Scanner s=new Scanner(System.in);
System.out.println("请输入年份----");
int a=s.nextInt();
System.out.println("请输入月份----");
int b=s.nextInt();
int day=0;
//可以输入,但是未完!!!
switch(b)
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day=31;
break;
case 4:
case 6:
case 9:
case 11:
day=30;
break;
case 2:
if((a%4==0&&(a%100!=0||(a%400==0))))
day=29;
else
day=28;
break;
System.out.println(a + "年" + b + "月份 " + "有" + day + "天");
以上是关于python输入年份月份输出天数_输入年份月份输出对应的天数的主要内容,如果未能解决你的问题,请参考以下文章
C语言 根据输入的年份和月份,判断输出是不是闰年和该月的天数,很急,谢谢!