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);

[1484 byte] By [tmlucky13a] at [2007-11-26 22:10:19]
# 1
Hints:Compare the lengths first, shorted words are usually sorted before longer ones. Loop over each letter, comparing them individually. When you find a charcter that comes before the other, that word comes before the other.
hunter9000a at 2007-7-10 10:57:48 > top of Java-index,Java Essentials,Java Programming...
# 2
> Compare the lengths first, shorted words are usually> sorted before longer ones. I don't think you meant to say that, did you? Would you sort "you" before "meant"?
DrClapa at 2007-7-10 10:57:48 > top of Java-index,Java Essentials,Java Programming...
# 3

> > Compare the lengths first, shorted words are

> usually

> > sorted before longer ones.

>

> I don't think you meant to say that, did you? Would

> you sort "you" before "meant"?

Wow, no, that didn't make sense. I was thinking of sorting "you" before "your", don't know why I screwed that up. How about this:

Loop over each letter, comparing them individually. When you find a charcter that comes before the other, that word comes before the other. If you reach the end of one word, that word comes first.

hunter9000a at 2007-7-10 10:57:48 > top of Java-index,Java Essentials,Java Programming...