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!
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

Reagan Govender
845 PointsString instead of char?
The video has this line of code;
String guessInput = scanner.nextLine();
char guess = guessInput.charAt(0);
return game.applyGuess(guess);
Would this not be better? if not why?
char guessInput = scanner.nextLine();
return game.applyGuess(guessInput);
1 Answer
William Li
Courses Plus Student 26,867 Pointsthis method scanner.nextLine()
returns a String, hence, this value can't be assigned to guessInput if guessInput is a char. This has to do with the fact that Java is a strongly typed language, if a variable is assigned a new value, that new value needs to be of the same type w/ the variable, otherwise it's syntax error.