要产生随机数,可以使用Java api中java.lang包中的Math类.Math类以静态方法的方式提供常用的数学方法,
其中Math.random()方法是一个可以产生[0.0,1.0]区间内的一个双精度浮点数的方法
如:
产生一个100以内的整数:int x=(int)(Math.random()*100);
又如:
产生一个1-50之间的随机数:int x=1+(int)(Math.random()*50)

相关文章:

  • 2022-12-23
  • 2022-02-10
  • 2022-01-14
  • 2021-12-27
  • 2022-12-23
  • 2021-06-12
  • 2021-06-30
猜你喜欢
  • 2021-11-28
  • 2022-02-09
  • 2021-12-18
  • 2021-07-07
  • 2022-02-28
相关资源
相似解决方案