java查询月份天数

import java.util.Scanner;;
public class Yang1014 {
public static void main(String[] args) {
//要求使用switch结构,根据传递的表示月份的参数,显示该月有多少天,假设2月为28天,不考虑闰年问题.

System.out.printf(“请输入要查找的月份(1~12):”);
int i=new Scanner(System.in).nextInt();
switch(i) {
case 1:
System.out.println(“该月有31天!”);
break;
case 2:
System.out.println(“该月有28天!”);
break;
case 3:
System.out.println(“该月有31天!”);
break;
case 4:
System.out.println(“该月有30天!”);
break;
case 5:
System.out.println(“该月有30天!”);
break;
case 6:
System.out.println(“该月有31天!”);
break;
case 7:
System.out.println(“该月有30天!”);
break;
case 8:
System.out.println(“该月有31天!”);
break;
case 9:
System.out.println(“该月有31天!”);
break;
case 10:
System.out.println(“该月有30天!”);
break;
case 11:
System.out.println(“该月有31天!”);
break;
case 12:
System.out.println(“该月有30天!”);
break;
}
}
}

猜你喜欢

转载自blog.csdn.net/weixin_44864260/article/details/102817054
今日推荐