public class NumRandom {
public static void main(String[] args) {
Set<Integer> set = new HashSet<>();
Random random = new Random();
while(true){
int num = random.nextInt(100);
set.add(num);
//判断集合个数
if (set.size() == 10){
break;
}
}
System.out.println(set);
}
}
随机生成10个0-100的数用Set集合存储并输出
最新推荐文章于 2023-04-03 21:47:25 发布