题解 | #明明的随机数#
明明的随机数
http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
public class Main {
//把输入得数字转化为数组 数组转set去重 通过Collections.sort 排序
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Set<Integer> set1 = new HashSet<>();
Integer arr[] = new Integer[n];
for (int i = 0; i < n; i++) {
set1.add(sc.nextInt());
// arr[i]= sc.nextInt(); } // Set set = Arrays.stream(arr).collect(Collectors.toSet()); List ls = new ArrayList(set1); Collections.sort(ls);
ls.forEach(item -> System.out.println(item));
}
}