• Post Reply Bookmark Topic Watch Topic
  • New Topic

Beginner Java - Lexicographic Ordering, I'm almost there!  RSS feed

 
Francais Libble
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys! Beginner Java Programmer here. I have a assignment to do some Lexigraphic ordering. I have figured how to get the majority of this done, however, when I input my string values. No output takes place? :s
If anyone can provide me with some help that be greatly appreciated!


Output is supposed to be similar to this:
Enter first string: Hello
Enter second string: Heather
Lexicographically, Heather comes before Hello
OR
Enter first string: Heather
Enter second string: Hello
Lexicographically, Heather comes before Hello

Enter first string: January
Enter second string: June
Lexicographically, January comes before June


 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here is an excerpt from me running your program


So I can get the FIRST message.
I can't get the second one though. Maybe double check that second if statement?
I would recommend printing out a message on all paths through the program so that you can actually see that it is doing things.

 
Francais Libble
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:
Here is an excerpt from me running your program



So I can get the FIRST message.
I can't get the second one though. Maybe double check that second if statement?
I would recommend printing out a message on all paths through the program so that you can actually see that it is doing things.



I think I got it now! Code below seems to logically justify.




Another question I have is, What is a simpler way to do this? This seems a bit tedious to perform functions this way. I always have a knack to find a quicker way to do things simply.
 
Janeice DelVecchio
Bartender
Posts: 1812
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an easier way.

If you notice, you're doing the same thing in all three paths. With a slight difference.
Can you spot the repetition? you should be able to "don't repeat yourself" and refactor out the duplicate code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!