aspose file tools*
The moose likes Beginning Java and the fly likes wordFinder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "wordFinder" Watch "wordFinder" New topic
Author

wordFinder

eLL Pascual
Greenhorn

Joined: May 22, 2008
Posts: 21
I really want to make a program that is accepting integer values and I want that program to print all possible letter combinations assigned to each number or maybe not all. Just like when you type 23, the program should print "ad ae af bd be bf cd ce cf".

How can I do that?

Please help me. Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42629
    
  65
I don't understand how one gets from "23" to the list you mention. Can you describe the algorithm to us?

What do you have so far?


Ping & DNS - my free Android networking tools app
eLL Pascual
Greenhorn

Joined: May 22, 2008
Posts: 21
Im sorry for not explaining my problem very clearly...
In your nokia cellphone, there are corresponding letters in every number right?

That's how the number 23 got the letters ad ae af etc... the program will print all possible letter combinations.

These are the letters:
number 1: special characters
number 2: abc
number 3: def
number 4: ghi
number 5: jkl
number 6: mno
number 7: pqrs
number 8: tuv
number 9: wxyz
number 0: space

I haven't started yet because I dont know how.
Actually I already tried it. I used nesting for loop and if-else but the problem is my program is not printing anything correctly. So my problem is merely everything.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18994
    
  40

Have you tried a recursive solution? This is a classic homework problem for recursion.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 690
    
    1
Sounds like a nested loop problem, except the number of nestings isn't fixed.
If it were fixed, say at 2 as per your example, there would be a nested loop with the outer one picking up one letter at a time and the inner loop then appending one letter at a time to the one from the outer loop.
Now think how to do this using recursion. Put the letters into a 2 dimensional array with the first index being the number and the second index being the letters for that number.
This is off the top of my head, of course.
 
Consider Paul's rocket mass heater.
 
subject: wordFinder