File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes String Unscrambler issues (Self-Resolved) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Unscrambler issues (Self-Resolved)" Watch "String Unscrambler issues (Self-Resolved)" New topic
Author

String Unscrambler issues (Self-Resolved)

john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495



It is printing out all the possible values instead of just one word. For example, if word1 = "is", then it will print out "is" and "si". If word1 is "will", the results will be


What is the problem and how do I fix it?
Thanks,
cc11rocks aka John Price


“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11443
    
  16

Why don't you start by telling us what you are trying to do, rather than make us guess?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

I am making an "Unscrambler". Basically, it should pick up a String, then compare it to the list of words. If you type in "lliw", it should print out "will". If you type in "wlli", it should still print out "will". What is actually happening is above.
Thanks,
John Price aka cc11rocks

EDIT: I just figured it out! Had to do two fixes:

Thanks,
cc11rocks aka John Price
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18708
    
    8

It's good that you got the code to work. However...

That code appears to compare the input string to all possible permutations of the letters in each word of the list. There's a process which only requires one comparison for each word in the list; this would be both faster (there are 5,040 permutations of a 7-letter word) and easier to read. I won't tell you what it is, just that it requires pre-processing each word in the list to make that comparison possible.
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Do I change line 26 to:

?
Thanks,
cc11rock aka John Price

EDIT: I found a noticeable time improvement with this above code (the new change to line 26).
 
jQuery in Action, 2nd edition
 
subject: String Unscrambler issues (Self-Resolved)