用Java编写一个能对一组字符串按字典序升序排序的程序 输入为N和N行字符串,需要按行输出字符串升序排序的结果 如输入
3
Abc
Abe
Abd
输出:
Abc
Abd
Abe
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//字符串数组 再对字符串数组进行排序?!
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String[] s = new String[n];
String t = sc.nextLine();//读取3之后的空行
for(int i = 0; i < n; i++) {
s[i] = sc.nextLine();
}
Arrays.sort(s);
//System.out.println(Arrays.toString(s));
for(int i = 0; i < n; i++) {
System.out.println(s[i]);
}
}
}