1 public static void main(String[] args) {
//set集合存储不重复无序的值 2 Set<Integer> set = new HashSet<Integer>(); 3 Random random = new Random(); 4 boolean panduan = true; 5 while (true) { 6 int z = random.nextInt(43);
//set.add();返回boolean值 7 panduan = set.add(z); 8 if (!panduan) { 9 continue; 10 } 11 if (set.size() >= 7) { 12 break; 13 } 14 15 } 16 17 System.out.println(set); 18 19 }