program that asks for two strings and reports their lexicographical order
I need some help with this program. I use compareto in my program, but my teacher does not want us to use that. So how do I do this program using CharAt and length string class. Can somebody get me started. Thanks
A program that asks for two strings and reports their lexicographical ordering, i.e. as they would appear in a lexicon that sorts them according to ASCII values. Do not use any predefined string comparison methods! The only predefined methods you may use are nextLine() of the Scanner class and length() and charAt(int i) of the String class.
EXTRA CREDIT: allow the user to decide whether they want to ignore case in the comparison (again without using predefined methods). Make sure you get the program working first without this feature.
Examples not ignoring case:
"abc" == "abc", "ABC" < "abc", "fishery" > "fish", "run?" > "run!"...
Examples ignoring case:
"abc$" == "ABC$", "Hat" == "haT", "cat" < "Hat", "Hatter" > "hat", ...
public class StringCompare
{
public static void main(String[] args)
{
String s1 = "abc",
s2 = "def";
// Compare "abc" and "def"
if (s1.compareTo(s2) < 0)
{
System.out.println(s1 + " comes before " + s2);
}
else if (s1.compareTo(s2) == 0)
{
System.out.println(s1 + " is equal to " + s2);
}
else if (s1.compareTo(s2) > 0)
{
System.out.println(s1 + " follows " + s2);

