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

I'am not able to understand a thing please make me understand help!!!

public boolean promptForGuesses() { Scanner scanner = new Scanner(System.in); System.out.println("Enter your letter: "); String guessInput = scanner.nextLine(); char guess = guessInput.charAt(0); isHit = game.hitOrmiss(guess); plz tell why char guess = guessInput.charAt(0); is used in the above code in the topic MVP in java and what is the need of this code over there....plz help. And what is it significance

1 Answer

guess = guessInput.charAt(0); is used as a safety precaution. The player is meant to write one-single character, but in case he writes a word instead, charAt(0) is going to extract the character at index-0 in that word, or in human terms: the first character so that the game can be played gracefully.

Thanx for your help...But if don't put it i assume there wouldn't be any harm . am i right