Hi! I am very new to Java. This is my first time taking a class on it and for an assignment I have to make a game that generates a random number and has the player guess it within 4 tries. Unfortunately, I cannot figure out how to generate a random letter. I have been searching for around an hour and cannot figure it out! From what I have gathered, I have make a string containing my letters.

Then, I am supposed to assign the randomly generated number to it's letter equivalent. And this is where I'm lost. I have no idea where to go from this point. I can't seem to figure out what code I can use to assign the number to it's corresponding letter. Any help is GREATLY appreciated! Thanks so much!

PS: I'm sorry if this has been a recurring question. I have looked in so many forums and read so many different threads, that my brain feels all squishy. So please don't hate me too much for this.

01-30-2011, 08:28 PM

eRaaaa

letters[num] :confused:

01-30-2011, 08:30 PM

Vase

The number you generated is between 0 and 25, which is perfect, because that corresponds to the elements in the array you created.

Say the number you generated is 4, and you want this to be converted to "E" (where 0 is "A").

Code:

String choice = letters[num];

will assign the letter at element [num] to the choice. Generate a 3, you have "D". Generate a 25, you have "Z".

When I was One,
I had just begun.
When I was Two,
I was nearly new.
When I was Three
I was hardly me.
When I was Four,
I was not much more.
When I was Five,
I was just alive.
But now I am Six,
I'm as clever as clever,
So I think I'll be six now for ever and ever.