美文网首页
switch语句练习

switch语句练习

作者: 哈迪斯Java | 来源:发表于2021-10-13 16:07 被阅读0次

    package HspLearning;

    import java.util.Scanner;

    public class Switch02 {
    public static void main(String[] args) {
    Scanner myscanner = new Scanner(System.in);
    System.out.println("请输入月份(1~12):");
    int month = myscanner.nextInt();
    switch (month){
    case 1:
    case 2:
    case 3:
    System.out.println("该月份为春季");
    break;

            case 4:
            case 5:
            case 6:
                System.out.println("该月份为夏季");
                break;
    
            case 7:
            case 8:
            case 9:
                System.out.println("该月份为秋季");
                break;
    
            case 10:
            case 11:
            case 12:
                System.out.println("该月份为冬季");
                break;
    
            default:
                System.out.println("您输入的月份有误,程序结束!");
        }
        myscanner.close();
    }
    

    }

    相关文章

      网友评论

          本文标题:switch语句练习

          本文链接:https://www.haomeiwen.com/subject/ohqeoltx.html