Go re-order

Source: Internet
Author: User

Obviously want to ask some students in school to do a questionnaire survey, in order to the objectivity of the experiment, he first used a computer to generate N 1 to 1000 random integer (n≤100), for the repeated numbers, only one, the rest of the same number is removed, the different numbers correspond to different student's number. Then the numbers from small to large sorting, in line with the order to find students to do the investigation.     Please help clearly to complete the "go to Heavy" and "sort" work. Input Param N Enter the number of random numbers inputarray n random integer array Return Value outputarray output after processing Random integer Note: The test case guarantees the correctness of the input parameters and the answer does not need to be verified.

importjava.util.*;

public class Main{      public static void main(String[] args){          Scanner in =  new Scanner(System.in);          while (in.hasNextInt()){              Set<Integer> set =  new HashSet<>();              int n = in.nextInt();              for ( int i= 0 ;i<n;i++){                  set.add(in.nextInt());              }              List<Integer> list =  new ArrayList<>();              list.addAll(set);              Collections.sort(list);              for ( int i:list){                  System.out.println(i);              }          }      } }Import java.util.*;
/**
* Created by Huaxia Ziyun on 2015/11/23.
*/
public class Main {
public static void Main (string[] args) {
Scanner sc=new Scanner (system.in);
while (Sc.hasnext ()) {
int N=sc.nextint ();
Hashset<integer> hashset=new hashset<integer> ();
for (int i=0;i<n;i++) {
Hashset.add (Sc.nextint ());
}
Arraylist<integer> arraylist=new arraylist<integer> ();
Iterator<integer> Iterator=hashset.iterator ();
while (Iterator.hasnext ()) {
Arraylist.add (Iterator.next ());

}
Collections.sort (arrayList);
StringBuffer sb=new StringBuffer ();
for (int i=0;iSb.append (Arraylist.get (i) + "");
System.out.println (Arraylist.get (i));
}
System.out.println (Sb.substring (0,sb.length ()-1));
}
}
Enter a few numbers first 512 34 12 56 78 output 12 34 56 78

Go re-order

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.