明明想在學校中請一些同學一起做一項問卷調查,爲了實驗的客觀性,他先用計算機生成了N個1到1000之間的隨機整數(N≤1000),對於其中重複的數字,只保留一個,把其餘相同的數去掉,不同的數對應着不同的學生的學號。然後再把這些數從小到大排序,按照排好的順序去找同學做調查。請你協助明明完成“去重”與“排序”的工作。
Input Param
n 輸入隨機數的個數
inputArray n個隨機整數組成的數組
Return Value
OutputArray 輸出處理後的隨機整數
import java.util.Scanner;
import java.util.TreeSet;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int num = sc.nextInt();
TreeSet<Integer> tc = new TreeSet<Integer>();
for(int i = 0;i<num;i++){
int cur = sc.nextInt();
tc.add(cur);
}
for(Integer i:tc){
System.out.println(i);
}
}
}
}