字符串排序
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
输入3个字符串,按字典序从小到大进行排序。
Input
输入数据有一行,分别为3个字符串,用空格分隔,每个字符串长度不超过100。
Output
输出排序后的三个字符串,用空格分隔。
Sample Input
abcd cdef bcde
Sample Output
abcd bcde cdef
Hint
Source
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
String aa,bb,cc;
aa = input.next();
bb = input.next();
cc = input.next();
if(aa.compareTo(bb) > 0) { //aa的字典序大于bb的字典序,则交换两者变量
String dd = aa;
aa = bb;
bb = dd;
}
if(aa.compareTo(cc) > 0) {
String dd = aa;
aa = cc;
cc = dd;
}
if(bb.compareTo(cc) > 0) {
String dd = bb;
bb = cc;
cc = dd;
}
System.out.println(aa+" "+bb+" "+cc);
input.close();
}
}