This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes And how do I do this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "And how do I do this?" Watch "And how do I do this?" New topic
Author

And how do I do this?

Manuel Diaz
Ranch Hand

Joined: Apr 22, 2005
Posts: 79
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.


Note: I love programming.
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
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

Joined: Apr 22, 2005
Posts: 79
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

Joined: Apr 22, 2005
Posts: 79
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

Joined: Jan 14, 2005
Posts: 323
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: And how do I do this?
 
Similar Threads
Why This Error??
How can I do this?
Simple Palindrome Program
Help with an array
determine least number of keypress