题解 | #明明的随机数#
明明的随机数
http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
import java.util.Scanner;
import java.util.*;
import java.util.stream.Collectors;
public class Main{
public static void main(String[] args){ // 获取输入流 Scanner scanner = new Scanner(System.in); //定义一个整型数组, 用来存储输入的数组 List<Integer> list = new ArrayList<Integer>(); //判断是否含有输入: while(scanner.hasNext()){ //定义循环输入的次数 int count = scanner.nextInt(); //接着输入要循环输入的数字 for(int i =0; i<count; i++){ list.add(scanner.nextInt()); } } //去重 for(int i =0 ;i<list.size();i++){ for (int j =i+1;j<list.size();j++){ if(list.get(j) == list.get(i)){ list.remove(j); j--; } } } //排序 Collections.sort(list); for(int i=0;i<list.size();i++){ System.out.println(list.get(i)); } }
}