java 取1-100之间的99个不重复的随机数 然后输出没有被取出的数字 求大侠帮忙!!!

如题所述

import java.util.Random;
import java.util.Set;
import java.util.TreeSet;

public class Dog {

public static void main(String[] args) {

Random rand = new Random();

Set<Integer> set = new TreeSet<Integer>();

while(set.size() < 99){
int value = rand.nextInt(101);
if(value > 0){
set.add(value);
}

}

for(int i = 1; i <= 100; i++){
if(!set.contains(i)){
System.out.println("Digit between 1 and 100 not in the set: " + i);
}
}
}
}

--------------
Digit between 1 and 100 not in the set: 10
温馨提示:答案为网友推荐,仅供参考
相似回答