首先产生随机数代码
//产生随机数
Random random = new Random();
// [1,101) :随机输出1-1000之间的整数
int i2 = random.nextInt(1000)+ 1;
//第二种
int i = (int) (Math.random() * 1000 + 1);
可是。。
用treeset吧
import java.util.*;
public class Main {
public static void main(String[] args) {
TreeSet treeSet = new TreeSet();
Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();
for (int i1 = 0;i1<i;i1++){
int i2 = scanner.nextInt();
treeSet.add(i2);
}
Iterator iterator = treeSet.iterator();
while (iterator.hasNext()){
System.out.println(iterator.next());
}
}
}