java 取1-100之间的99个不重复的随机数 然后输出没有被取出的数字 求大侠帮忙!!!
1个回答
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询