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 trialJoel Lithgow
7,414 PointsGuess as Char instead of String?
Why don't we make the guess as a Char instead of guessing as a string and turning it into a char?
2 Answers
Jon Kussmann
Courses Plus Student 7,254 PointsHi Joel,
I believe you are getting your original input from the user? If so, it will come to you as a String and so you will probably need to convert to a char either prior to using that method, or within the method. I think doing the conversion within that method makes the calling method have not so many "parts" to it, but I cannot remember specifically. If you need more explanation, could you post the relevant code?
Benjamin Gooch
20,367 PointsThis makes sense now. You recieve the input from the user as a String and store it in guessAsString, then you create a "guess" variable of the char type and store the character at the first index (should be the only char in the input) in that variable using guessAsString.charAt(0).
Joel Lithgow
7,414 PointsJoel Lithgow
7,414 Pointsthat solves my question thank you, I was not aware that all user inout came as a String, and wondered if there was just a single char for the input you could fall back to that instead.