例如,获取30 到80之间的随机整数,包括30和80.

Random r=new Random();

 int t=30+r.nextInt(51);

即采用的方式是 从A到B之间的随机数,则使用 A+r.nextInt(B-A+1) 得到。

相关文章:

  • 2022-02-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2022-01-01
猜你喜欢
  • 2021-07-16
  • 2022-12-23
  • 2021-09-19
  • 2022-01-13
  • 2022-12-23
  • 2021-12-18
相关资源
相似解决方案