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 Java Basics Getting Started with Java IO

Does the readLine method only return String data?

So, I typed 333 as my input when the readLine method was called and it worked, why? (Even though the returned value was stored in a String variable)

Yes, the readLine() method only returns a String value. So typing 333 as the input on the readLine is equivalent to setting a variable to "333" in your Java code. If you needed to get the integer datatype from the readLine method, you would first need to return a String value and then convert it to an integer using parseInt(), like so:

String input = console.readLine("Enter input");
int inputToInt = Integer.parseInt(input);
// inputToInt now equals 333 instead of "333"

Hope that helps

1 Answer

It helped, thanks!