This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "wordFinder" Watch "wordFinder" New topic


eLL Pascual

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

Joined: Mar 22, 2005
Posts: 42965
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?
eLL Pascual

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

Joined: Sep 28, 2004
Posts: 20538

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


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

Joined: Aug 10, 2005
Posts: 696
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.
I agree. Here's the link:
subject: wordFinder
It's not a secret anymore!