public static void main(String[] args)
{
Random random = new Random();
HashSet<Integer> set = new HashSet<Integer>();
int t;
for(int i=0;i<10;){
t=random.nextInt(20)+81;
if(!set.contains(t)){
set.add(t);
i++;
}
}
for (Integer i : set) {
System.out.print(i+" ");
}
}
1:利用Set的唯一性 使用循环创造随机数并添加Set 当Set长度大于9跳出循环
2 JDK API文档全都有
3 Student 类实现比较类接口
稍微找一下关于 Set 的知识都可以做出来,何必在这里等着吃现成的,搞不懂现在的学生。