第一种方法

Random r=new Random();
int a=r.nextInt(16)+1;

解析

r.nextInt(16)会生成0-15

第二种方法
int num = (int) (Math.random() * 16 + 1);

解析

Math.random()会随机生成[0,1),大于等于0小于1

当随机生成0时,Math.random() * 16为0

当随机生成0.99时,Math.random() * 16为15.84

相关文章:

  • 2021-12-18
  • 2021-08-13
  • 2021-11-29
  • 2021-12-11
猜你喜欢
  • 2021-10-20
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
  • 2021-12-18
  • 2021-12-18
  • 2021-12-18
相关资源
相似解决方案