用Math.random()方法生成随机数

生成的区间为[0,1);

//计算随机数公式:*(最大值-最小值+1)+最小值

//求200到18之间的随机数

//double rendom=Math.random();

//System.out.println(rendom);

for(int i=0;i<10;i++) {

int num=(int)(Math.random()*((200-18)+1)+18);//强转为int类型

System.out.println(num);

猜你喜欢

转载自blog.csdn.net/weixin_40873693/article/details/78482984