蓝桥杯- 基础练习:数列排序

 

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int cNumber = scanner.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < cNumber; i++) {
            list.add(scanner.nextInt());
        }
        Collections.sort(list);
        String replace = list.toString().replaceAll("[\\[\\],]","");
        System.out.println(replace);
    }
}
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        //数组排序
        Scanner scanner = new Scanner(System.in);
        int cNumber = scanner.nextInt();
        int nums[] = new int[cNumber];
        for (int i = 0; i < cNumber; i++) {
            nums[i]=scanner.nextInt();
        }
        Arrays.sort(nums);
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i]+" ");
        }
    }
    
}
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int cNumber = scanner.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < cNumber; i++) {
            list.add(scanner.nextInt());
        }
        list.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer arg0, Integer arg1) {
                return Integer.compare(arg0, arg1);
            }
        });
        String replace = list.toString().replace("[", "");
        String replace2 = replace.replace("]", "");
        String replace3 = replace2.replace(",", "");
        System.out.println(replace3);
    }
}

 

posted @ 2018-01-13 21:22  Bap  阅读(431)  评论(0编辑  收藏  举报