• 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

And how do I do this?

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I want to make a program that read a text input by the user. For example, I need this letters for the program (h,e,l,p), I want the program that convert those letters into numbers, I have this code:



OK, that's fine, but it seems odd to me. Can I make an array to check the letters, like this:

array = {h,e,l,p};
number = {0,1,2,3};

If the user inputs one of those letters, the program finds on the array of numbers, the number that correspond with that letter. Can someone help me??

THANKS IN ADVANCE.
 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the word "help" has no repeated letters — that is, every letter in it occurs only once in it. so long as that remains true (so long as you don't switch to some other word that does have repeated letters) the String.indexOf() method might prove useful.
 
Manuel Diaz
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please be more specific?

Supose that the user inputs: h89

I split the word and then how can I use String.indexOf() to say that the 'h' has to become and '0' for example?
 
Manuel Diaz
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK,I finally found that part. But what about if I want it in the inverse?. The user inputs a number: 1

Then the program has to check in the variable number "12345678". Now I want to convert that 1 the user inputs into a, 2 into b, 3 into c. Any suggestions?
 
M Beck
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, if you've figured out how to use .indexOf() to go from 'e' to 2 in the word "help" (or actually i think you'll be going from 'e' to 1, since the indexes that indexOf() returns are zero-based; just add 1 to fix that), then going back is equally easy. you'll want to read about the String.charAt() method, and keep in mind you'll have to convert the indexes to being zero-based first; that just means subtracting 1.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic