Huawei's R & D engineers programming that 2

Obviously want to invite some students in the school together to do a survey, in order to test the objectivity, his first with the computer-generated random integer (N≤1000) between 1 and 1000 N number,

Wherein for duplicate numbers, but one, to remove the rest of the same number, corresponding to the number of different students learn different number.

Then put these numbers in ascending order, to get the students to do research in accordance with good row order.

Please help obviously complete "de-duplication" and "sort" work (with a test case where there may be multiple sets of data, we hope to be able to handle correctly).

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scaner = new Scanner(System.in);
        while(scaner.hasNext()){
            int count = scaner.nextInt();
            int[] nums = new int[count];
            for(int i =0;i<count;i++){
                nums[i]=scaner.nextInt();
            }
            sort(nums);
        }
    }
     
    private static void sort(int[] nums){
        boolean[] flags = new boolean[1001];
        for(int i = 0;i<nums.length;i++){
            flags[nums[i]] = true;
        }
        for(int i = 0;i<flags.length;i++){
            if(flags[i]){
                System.out.println(i);
            }
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/fly1024/p/12577766.html