题解 | #字符串排序#

字符串排序

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int size= in.nextInt();//确定字符串个数
        in.nextLine();//在nextInt先使用,nextLine后使用的情况下,要提前使用nextLine清除回车。
        String[] strs=new String[size];//开辟字符串数组容器
        for(int i=0;i<size;++i){
             strs[i]=in.nextLine();
        }
        Arrays.sort(strs);//自带的排序算法,排序
        for(String s:strs){
            System.out.println(s);//遍历输出
        }
        
    }
}

全部评论

相关推荐

有气魄的马来熊在摸鱼:我爱vivo 马上换手机 vivo我爱你!!!
点赞 评论 收藏
分享
11-14 16:15
已编辑
湖南工业大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务