字符串排序
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 a, b, c;
String d;
a = input.next();
b = input.next();
c = input.next();
if(a.compareTo(b) > 0) {
d = a;
a = b;
b = d;
}
if(a.compareTo(c) > 0) {
d = a;
a = c;
c = d;
}
if(b.compareTo(c) >0) {
d = b;
b = c;
c = d;
}
System.out.println(a+" "+b+" " + c);
}
}