随机生成的数字怎样和Switch结合

img


随机生成的数字如何和Switch形成关系,这个输出的数字就只是单单的数字,要输出Switch还要输入数字

随机数产生的是 数字类型,不是字符串类型呀,生成随机数 Math.random就可以了

public static void main(String[] args) {
        int random=(int)(Math.random()*8+1);
        switch(random) {
            case 0:
            case 1 :System. out.println("天意如此,那就一饭吧! ") ;break;
            case 2:
            case 3: System. out.println("天意如此,那就二饭吧! ");break;
            case 4:
            case 5 :System.out.println("天意如此,那就三饭吧! ");break;
            case 6:
            case 7:System.out.println("天意如此,那就四饭吧! ");break ;
            case 8: System.out.println("出去吃吧! ");break ;
            default : System. out.print("今天就叫外卖吧! ");
        }
    }