题解 | #字符串排序#

字符串排序

http://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723

核心代码块:Arrays.sort(arr, String::compareTo);


import java.util.Arrays;
import java.util.Scanner;

/**
 * @author
 * Created by Administrator on 2022-05-06 03:55
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int num = sc.nextInt();
            String[] arr = new String[num + 1];
            for (int i = 0; i <= num; i++) {
                arr[i] = sc.nextLine();
            }
            Arrays.sort(arr, String::compareTo);
            for (int i = 1; i <= num; i++) {
                System.out.println(arr[i]);
            }
        }


    }
}
全部评论

相关推荐

10-11 15:42
皖西学院 Java
青鱼LINK:我硕士,也是java0面试,吾道不孤
点赞 评论 收藏
分享
点赞 1 评论
分享
牛客网
牛客企业服务