Welcome to the Treehouse Community
Looking to learn something new?
gurveer aulakh2,800 Points
in the prompter class what is the use of the below code in PromptForGuess method: char guess = guessInput.charAt(0); As I got confused on that line because why are we asking to get the first letter of the word.
if the confusion is related to the use of 0 in this like
char guess = guessInput.charAt(0);
Then this is because java is zero(0) based index language ... same a s C and C#,
therefore, if I have an array of 3 elements ,,, le cally myArry. the the array contents are:
myArry. myArry, myArry
you can think of a string a an arry of Char. Therefore is a have a string "this is my string" and I wan to get the first char in this string, then I would
char myChar= "this is my string".charAt(0);
myChar will hold the letter 't'
Hope this helps clarifies
Mustafa Alordowny4,495 Points
this line is used to assign the value of the first letter in the string guessInput to the character named guess.