题解 | #字符串排序#
字符串排序
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);//遍历输出
}
}
}