For each case, the first line of the input contains an integer number N representing the quantity of numbers in this array(1≤N≤1000). Next N lines contain N integer numbers(one number per each line) of the original array.
For each case ,outtput file should contain at most N numbers sorted in ascending order. Every number in the output file should occur only once.
6 8 8 7 3 7 7
3 7 8
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; import java.util.stream.Stream; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { int n = sc.nextInt(); List<Integer> list = new ArrayList<>(); for(int i=0;i<n;++i) { list.add(sc.nextInt()); } Stream stream = list.stream(); stream.distinct().sorted().forEach(i->System.out.print(i+" ")); } } }
import java.util.Scanner; import java.util.TreeSet; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); TreeSet<Integer> set = new TreeSet<>(); for (int i = 0; i < n; i++) set.add(scanner.nextInt()); for (Integer integer : set) System.out.print(integer+" "); } }