Go re-order

Source: Internet
Author: User

Input Description:

Enter multiple lines, first enter the number of random integers, and then enter the corresponding number of integers

Output Description:

Returns multiple rows, processed results

Input Example 1:
11102040326740208930040015
Output Example 1:
10152032406789300400
Use HashSet and TreeSet respectively to achieve
Import Java.util.arraylist;import java.util.collections;import Java.util.hashset;import Java.util.Iterator;import Java.util.scanner;public class M2 {public static void main (string[] args) {Scanner scanner=new Scanner (system.in); Scanner.hasnext ()) {hashset<integer> alist=new hashset<integer> (); int i=scanner.nextint (); for (int j=0; j < I; J + +) {Alist.add (Scanner.nextint ());} Iterator Iterator=alist.iterator (); arraylist<integer> n =new arraylist<integer> (); for (int j = 0; J < Alist.size (); j + +) {N.add ((Integer) ITER Ator.next ());} Collections.sort (n); for (int m = 0; m < alist.size (); m++) {System.out.println (N.get (M));}}}

while (Sc.hasnext ()) more than one input

Import Java.util.scanner;import Java.util.treeset;public class M3 {public static void main (string[] args) {Scanner Scanne R=new Scanner (system.in); while (Scanner.hasnext ()) {treeset<integer> alist=new treeset<integer> (); int i= Scanner.nextint (); for (int j=0; j< i; j + +) {Alist.add (Scanner.nextint ());} for (Integer m:alist) {System.out.println (M);}}}}

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.