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 trialGalara Coding
624 Pointswhy did we make a new variable for the charAt(0) method
why we used this line:
char guessInput = scanner.nextLine().charAt(0);
instead of these two lines:
char guessInput = scanner.nextLine();
char guess = guessInput.charAt(0);
I try it and it works.
what is the difference?
2 Answers
KRIS NIKOLAISEN
54,971 PointsYou can eliminate intermediate variables with method chaining. Because this technique wasn't covered two lines of code were used instead.
douaa atouailaa
6,120 PointsThe two lines and the one line solutions give the same result, but with the two lines solution we are allocating an additional variable that we can eliminate since it is used only once to give us another value, allocating a variable means allocating memory and additional reference that we don't really need and we can ultimately avoid via method chaining.
Galara Coding
624 PointsGalara Coding
624 Pointsok thanks