007.Switch语句(3月,本该是春天的季节。)
1.代码
package com.lll.demo; import java.util.Scanner; public class Demo2 { public static void main(String[] args) { System.out.print("请输入一个月份:"); int month = new Scanner(System.in).nextInt(); String season; switch (month) { case 12: case 1: case 2: season = "冬天"; break; case 3: case 4: case 5: season = "春天"; break; case 6: case 7: case 8: season = "夏天"; break; case 9: case 10: case 11: season = "秋天"; break; default: season = "Bogus Month"; } System.out.println(month + "月是" + season); } }
2.运行结果