Alphabetical Order

Lab Java Intermediate 20 points

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
Sample input available Sample output available
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);
        }
    }
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD