代码拉取完成,页面将自动刷新
import java.util.*;
public class GetRandomNumber {
public static int [] getRandomNumber(int max,int amount) {
//1至max之间的amount个不同随机整数(包括1和max)
int [] randomNumber = new int[amount];
int index =0;
randomNumber[0]= -1;
Random random = new Random();
while(index<amount){
int number = random.nextInt(max)+1;
boolean isInArrays=false;
for(int m:randomNumber){//m依次取数组randomNumber元素的值(见3.7)
if(m == number)
isInArrays=true; //number在数组里了
}
if(isInArrays==false){
//如果number不在数组randomNumber中:
randomNumber[index] = number;
index++;
}
}
return randomNumber;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。