题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
import java.util.Scanner; import java.util.Arrays; import java.util.HashSet; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int len = sc.nextInt(); int[] arr1 = new int[len]; for (int i = 0; i < arr1.length; i++) { arr1[i] = sc.nextInt(); } pai(arr1); } public static void pai(int[] arr) { HashSet<Integer> s1 = new HashSet<>(); for (int i = 0; i < arr.length; i++) { s1.add(arr[i]); } int[] arr1 = new int[s1.size()]; int a = 0; for (Integer integer : s1) { arr1[a++] = integer; } Arrays.sort(arr1); for (int i = 0; i <arr1.length; i++) { System.out.println(arr1[i]); } } }