题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt();//第一个数为int型的 scanner.nextLine(); // 消耗掉换行符,避免影响后续输入读取 String[] strings = new String[n]; for (int i = 0; i < n; i++) { strings[i] = scanner.nextLine(); }//输入进数组 Arrays.sort(strings);//排序 for (String str : strings) { System.out.println(str); }//遍历输出 scanner.close(); } }