Foreword
- I have been conducting interviews recently. Many of the written code is too lazy to post to the blog. It is now filled in, but there may be fewer comments. If you have any questions, please contact me
- This question, the official intention is definitely not to let us simply complete a java existing package to complete, it is definitely to let us use bubble sorting, fast sorting to achieve this method, to test our knowledge of sorting, I Will be added after reviewing the sorting method
Exam questions basic practice sequence
Resource limit
Time limit: 1.0s Memory limit: 512.0MB
Problem description
Given a sequence of length n, arrange the sequence in ascending order. 1 <= n <= 200
Input format The
first line is an integer n.
The second line contains n integers, which are the numbers to be sorted, and the absolute value of each integer is less than 10000.
Output format
Output a line, and output the sorted sequence in ascending order.
Sample input
5
8 3 6 4 9
Sample output
3 4 6 8 9
import java.util.Arrays;
import java.util.Scanner;
public class SeqRanking {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
Arrays.sort(a);
for (int i = 0; i < n; i++) {
System.out.print(a[i] + " ");
}
/*for(int i: a){
System.out.print(i+" ");
}*/
}
}