问题描述
编写一个程序,用户第一行输入数字的个数n(1<=n<=1000),第二行输入n个用空格分隔的整数。程序按照升序对数字进行排序,并输出排序后的结果。
样例输入
5
3 10 9 5 8
样例输出
3 5 8 9 10
import java.util.Arrays;
import java.util.Scanner;
public class Main {
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.parallelSort(a);
for (int i = 0; i < a.length; i++) {
System.out.print(a[i]+" ");
}
}
}