一种用ArrayList方式的解法
先判断是否存在,再存入,最后排序输出:
import java.util.Scanner;
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int cnt = in.nextInt();
int demo = 0;
ArrayList<Integer> nums = new ArrayList<Integer>();
for(int i = 0; i < cnt; i++){
demo = in.nextInt();
if(nums.contains(demo) == false)
nums.add(demo);
}
nums.sort(Comparator.naturalOrder());
for(int i : nums)
System.out.println(i);
}
}