I've come across an issue whilst doing some homework. The problem is to take three strings and sort them. I've gotten this down for numbers but I don't know how to accomplish this with strings.
Here it is verbatim from the book:
Write a program that reads three strings and prints them in lexicographically sorted order.
Please enter three strings:
Tom
Dick
Harry
The inputs in sorted order:
Dick
Harry
Tom
My Tester:
package Chapter_5;
import java.util.Scanner;
public class StringOrderTester
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.println("Please provide three strings:");
StringOrder str = new StringOrder(in.nextLine(),in.nextLine(),in.nextLine());
}
}
My Code:
package Chapter_5;
public class StringOrder
{
public StringOrder(String str1, String str2, String str3)
{
String index;
int i = str1.compareTo(str2);
System.out.println(i);
}
}