java中获取指定范围内的随机数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34491508/article/details/81950085

    public static void main(String[] args) {
        //使用数字专用类Random,公式new Random().nextInt()(max-min+1)+min
        //生成10到30之间的数字
        int max= 30;
        int min = 10;
        int num = new Random().nextInt(max-min+1)+min;
        System.out.println(num);
    }

猜你喜欢

转载自blog.csdn.net/qq_34491508/article/details/81950085