用 random.nextint();这个方法啊 写一个用集合来操作的 遍历出来
public class Random {
public static void main(String[] args) {
Random random = new Random();
HashSet<Integer> hs = new HashSet<Integer>();
while(true){
hs.add(random.nextInt(20) + 1);
if (hs.size() == 10) {
break;
}
}
for (Integer a : hs) {
System.out.print(a + " ");
}
}
} |