-
题目
输入某某年,某某月,输出本月有多少天(包含是否有闰年) -
结果输出
3.代码
package cn.nokia.month;
import java.util.Scanner;
public class monthtest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner month1 =new Scanner(System.in);
System.out.println("请输入年份"); //输入年
int year=month1.nextInt();
System.out.println("请输入月份"); //输入月
int month=month1.nextInt();
if(year%4==0&&year%100!=0||year%400==0){
System.out.println(year+"是闰年");
}
else
{
System.out.println(year+"是平年");
}
switch(month){
default:
System.out.println("输入的月份超出范围");
break;
case 2:
int days=0;
if(year%4==0&&year%100!=0||year%400==0){
days=29;
System.out.println("2月的天数是:"+days+"天");
}else{
days=28;
System.out.println("2月天数是:"+days+"天");
}
break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days=31;
System.out.println(month+"月份的天数有"+days+"天");
case 4:
case 6:
case 9:
case 11:
days=30;
System.out.println(month+"月份的天数有"+days+"天");
}
}
}
网友评论