java中怎么随机生成3位整数.

来源:百度知道 编辑:UC知道 时间:2024/05/21 16:38:45
public int nextInt(1000)能生成0-999的随机整数,我想随机生成100-999的整数怎么办

public int getRandom() {
int number = 0;
while (true) {
number = (int) (Math.random() * 1000);
if (number >= 100 && number < 1000) {
break;
}
}
return number;
}

public int nextInt(900)+100;

random.randint(100,999),

int number=(int)(Math.random()*1000);