For my hangman game for class, I need to write each letter of a word into an array. How would I go about this?
Printable View
For my hangman game for class, I need to write each letter of a word into an array. How would I go about this?
Is your "word" a String object? And you want to create a char array whose contents correspond to the String?
Then look at the String.toCharArray() method.
If this does not help, then tell us exactly what it is that you have and what it is that you want to do.
Cheers!
Z
The word is a String in an array (finds one word by getting a random word from the array). What I need to happen is that the word (lets use the as an example) to be split into its seperate letters(t-h-e) and written into an array.
--- Update ---
for the toCharArray thing that you posted, do I need to name an array in the ()? Or how would I reference the created array? Thanks.
Read the API doc for the String class and its methods. It will help you write the code to use the method.
If you have questions about the contents of the API doc, copy the doc here and ask the questions.
String a="abc";
char c=a.charAt(0);
System.out.println(c);