zoukankan      html  css  js  c++  java
  • 蓝桥杯- 基础练习:数列排序

    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);
        }
    }
  • 相关阅读:
    想出去走走
    一辈子的孤单
    好久不见
    bash 源码分析
    如何查看bash shell 帮助信息?
    mvn使用笔记
    StringTemplate初步使用
    使用tungsten将mysql的数据同步到hadoop
    《大脑幸福密码》
    《跳出头脑,融入生活》
  • 原文地址:https://www.cnblogs.com/wzqjy/p/8280579.html
Copyright © 2011-2022 走看看