多行字符串按字典排序
import java.util.Arrays;
import java.util.Scanner;
/**
* HJ14 字符串排序
牛客网
*/
public class Main13 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
getDoubleArr(sc.nextInt(),sc);
}
public static void getDoubleArr(int length,Scanner sc){
int i=0;
String[] strings=new String[length];
while (length>i){
strings[i]=sc.next();
i++;
}
Arrays.sort(strings);
//输出结果
for(String s:strings){
System.out.println(s);
}
}
}
测试输入:
9
cap
to
cat
card
two
too
up
boat
boot
目标结果
boat boot cap card cat to too two up