The
problem description is given a sequence of length n, which arranges the sequence in small to large order. 1<=N<=200 input format first behavior an integer n.
The second row contains n integers, and the absolute value of each integer is less than 10000 for the number to be sorted. Output format output one line, the sorted sequence is output in order from small to large. Sample Input 5
8 3 6 4 9 Sample output 3 4 6 8 9
Collection Sort:
Importjava.util.ArrayList;ImportJava.util.Comparator;Importjava.util.List;ImportJava.util.Scanner; Public classSort1 { Public Static voidMain (string[] args) {Scanner Scanner=NewScanner (system.in); intCnumber =Scanner.nextint (); List<Integer> list =NewArraylist<integer>(); for(inti = 0; i < Cnumber; i++) {List.add (Scanner.nextint ()); } list.sort (NewComparator<integer>() {@Override Public intCompare (integer arg0, integer arg1) {returnInteger.compare (arg0, arg1); } }); String Replace= List.tostring (). ReplaceAll ("[\\[\\],]", ""); Regular replacement System.out.println (replace); }}
Compiler run Result:
Sort by series |
01-10 14:36 |
710B |
Java |
That's right |
100 |
218ms |
21.25MB |
Blue Bridge Cup-basic exercise: Java Sequence sorting problem