题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
import java.util.*;
import java.util.stream.Collectors;
/**
* @Auther: hyk
* @Date: 2024/7/14 19:05
* @Description: PACKAGE_NAME
* @Vesion: 1.0
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = 0;
if(in.hasNextInt()){
n = in.nextInt();
if(n>=1 ||n<=1000){
Set<Integer> setInt = new HashSet<>();
//Random rd = new Random();
for (int i = 0; i < n; i++) {
setInt.add(in.nextInt());
}
List<Integer> ls = new ArrayList<>(setInt);
Collections.sort(ls);
for (int i = 0; i < ls.size(); i++) {
System.out.println(ls.get(i));
}
}
else{
System.out.println("输入个数的N非1≤n≤1000");
}
}
}
}
查看13道真题和解析