java蓝桥杯练习 数组排序去重
资源限制
时间限制:1.0s 内存限制:512.0MB
问题描述
输入10个整数组成的序列,要求对其进行升序排序,并去掉重复元素。
输入格式
10个整数。
输出格式
多行输出,每行一个元素。
样例输入
2 2 3 3 1 1 5 5 5 5
样例输出
1
2
3
5
//java code
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Set<Integer> a=new TreeSet<Integer>();
for (int i = 0; i < 10; i++) {
a.add(sc.nextInt());
}
for (int x:a
) {
System.out.println(x);
}
}
}