您的位置:首页 > 其它

基础练习 BASIC-13 数列排序

2017-09-26 19:22 337 查看
问题描述

  给定一个长度为n的数列,将这个数列按从小到大的顺序排列。1<=n<=200

输入格式

  第一行为一个整数n。

  第二行包含n个整数,为待排序的数,每个整数的绝对值小于10000。

输出格式

  输出一行,按从小到大的顺序输出排序后的数列。

样例输入

5

8 3 6 4 9

样例输出

     3 4 6 8 9

import java.io.BufferedReader;
import j
9f7e
ava.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

public class Main{
public static void main(String[] args) throws IOException {
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
String s = bfr.readLine();
int n = Integer.parseInt(s);
String s1 = bfr.readLine();
String [] str = s1.split(" ");
int [] collection = new int
;
ArrayList<Integer> al = new ArrayList<Integer>();
for(int i=0; i<n; i++){
al.add(Integer.parseInt(str[i]));
}
Collections.sort(al);
for(int i=0; i<al.size(); i++){
System.out.print(al.get(i)+" ");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: