产生随机数random
Math.random()方法是一个可以产生[0.0,1.0]区间内的一个双精度浮点数的方法
产生一个100以内的整数:
int x=(int)(Math.random()*100);
产生一个1-50之间的随机数:
int x=1+(int)(Math.random()*50)
Math.random()方法是一个可以产生[0.0,1.0]区间内的一个双精度浮点数的方法
产生一个100以内的整数:
int x=(int)(Math.random()*100);
产生一个1-50之间的随机数:
int x=1+(int)(Math.random()*50)