Alphabetical Order
Completed
Read two words and print them in alphabetical (dictionary) order on one line, ignoring case when comparing.
Input
Two words.
Output
The words in order.
Example
Input
pear apple
Output
apple pear
Editor
Java
Hints
compareTo returns a negative number, 0, or a positive number.
Solution explanation
a.compareTo(b) < 0 means a comes before b.
Show solution
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
if (a.compareToIgnoreCase(b) <= 0) {
System.out.println(a + " " + b);
} else {
System.out.println(b + " " + a);
}
}
}