• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic