import java.util.Comparator;
import java.util.Random;
import java.util.TreeSet;
public class Paixu {
public static void main(String[] args) {
Random r=new Random();
class Rule implements Comparator<Integer>{
@Override
public int compare(Integer o1, Integer o2) {
if (o1 > o2) return -1;
if (o1 < o2) return 1;
return 0;
}
}
TreeSet<Integer> a=new TreeSet<>(new Rule());
while (a.size()<10){
a.add(r.nextInt(20)+1);
}
System.out.println(a);
}
}
【Java】生成十个不重复的随机数并降序输出
最新推荐文章于 2022-12-17 12:53:34 发布