Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Can't understand why Craig Dennis took that step.

in his tutorial Prompting guesses after String guess = guessInput.nextLine(); we wrote char guess = guess.chatAt(0); why did he even write that plz explain

1 Answer

Yanuar Prakoso
Yanuar Prakoso
15,196 Points

Are you in the course that making Hangman game? If that is the case Craig just want to make sure if a user input more than one characters, for instance the user input "aioueorstru" which all of these characters will be put into String variable guess, only the first character which in this case is 'a' will be eligible as guess.

Other characters will be ignored thus it will not be in record that other characters ever being used as guess so that if after that the user input 'i' as the guess it still valid.