a- import java.util.TreeSet;
- public class T14 {
- /**
- *获取10个1至20的随机数,要求随机数不能重复。
- */
- public static void main(String[] args) {
- TreeSet<Integer> ts = new TreeSet<Integer>();
- while(ts.size()!=10){
- double d = Math.random()*20+1;
- ts.add((int)d);
- }
- System.out.println(ts);
- }
- }
复制代码
|
|