數組排列去重
題目
問題描述
輸入10個整數組成的序列,要求對其進行升序排序,并去掉重複元素。
輸入格式
10個整數。
輸出格式
多行輸出,每行一個元素。
樣例輸入
2 2 3 3 1 1 5 5 5 5
樣例輸出
1
2
3
5
看我前面寫的日期問題
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class 數列排列去重 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
Set<Integer> ans=new TreeSet<Integer>();
//int[] a=new int[10];
for(int i=0;i<10;i++){
//a[i]=sc.nextInt();
ans.add(sc.nextInt());
}
for(int i:ans){
System.out.println(i);
}
}
}