<>输入年份和月份,输出该年月的天数

做题思路:

1,3,5,7,8,10,12月为31天
4,6,9,11月为30天
特别的2月,需要通过判断是否为闰年,来确定是28天还是29天!
import java.util.Scanner; public class days { public static void main(String[]
args){ Scanner s =new Scanner (System.in); System.out.println("请输入年份:"); int
year= s.nextInt(); System.out.println("请输入月份:"); int month= s.nextInt(); int day
=0; switch (month){ 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((year
%4==0)&&(year%100!=0)||(year%400==0)){ day=29; } else{ day=28; } break; } System
.out.println(year+"年"+month+"月有"+day+"天"); } }

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信