题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
题解
使用Arrays的sort排序。
代码
import java.util.Scanner; import java.util.Arrays; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); String[] arr = new String[n]; for (int i = 0; i < n; i++) { arr[i] = sc.next(); } Arrays.sort(arr); for (int i = 0; i < n; i++) { System.out.println(arr[i]); } } } }