输入一个数字,在控制台输出其对应的月份和该月份对应的天数。

package ch2;
import java.util.*;
public class SwitchOP {

	public static void main(String[] args) {
		System.out.println("请输入月份:");
		Scanner scanner=new Scanner(System.in);
		int month=scanner.nextInt();
		switch(month){
		case 1: System.out.println("一月有31天");break;
		case 2: System.out.println("二月有28/29天");break;
		case 3: System.out.println("三月有31天");break;
		case 4: System.out.println("四月有30天");break;
		case 5: System.out.println("五月有31天");break;
		case 6: System.out.println("六月有30天");break;
		case 7: System.out.println("七月有31天");break;
		case 8: System.out.println("八月有31天");break;
		case 9: System.out.println("九月有30天");break;
		case 10: System.out.println("十月有31天");break;
		case 11: System.out.println("十一月有30天");break;
		case 12: System.out.println("十二月有31天");break;
		default: System.out.println("无效月份.");
		}
	}

}

分支结构3

相关文章:

  • 2021-07-30
  • 2022-12-23
  • 2022-03-09
  • 2021-09-02
  • 2022-02-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-17
  • 2021-06-17
相关资源
相似解决方案