题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
import java.util.Scanner;
import java.util.Arrays;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//创建变量接受随机数个数,创建整型数组
int num = sc.nextInt();
int[] arr = new int[num];
for(int i = 0; i<arr.length;i++){
arr[i] = sc.nextInt();
}
//处理数组1.对数组进行排序
Arrays.sort(arr);
//去除数组中重复的数字
int[] newArr = new int[num];
int temp = 0;
newArr[temp] = arr[0];
for(int i = 0; i<arr.length;i++){
//只有数字不同时temp指针才会移动
if(newArr[temp]!=arr[i]){
newArr[temp+1] = arr[i];
temp++;
}
}
//输出处理好的数组
for(int i = 0; i<newArr.length;i++){
if(newArr[i]!=0)System.out.println(newArr[i]);
}
}
}
广发银行公司氛围 23人发布
查看30道真题和解析