• 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

wordFinder

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried a recursive solution? This is a classic homework problem for recursion.

Henry
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic