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 Perfecting the Prototype Parsing Integers

Why age entering by user is in string?

Why we have to take String as variable for input a number? Why not take a int for readLine?

Cevin Thomas
Cevin Thomas
3,577 Points

I believe (fairly new to this), that when you use the method readLine, anything that comes through the input from another user, is considered a String. I am not 100% sure.

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Cevin Thomas is 100% correct. Anything coming in from the console/command line will be a String. It's interesting to note that this is not exclusive to Java. This applies to just about every programming language I've ever come across. In fact, I can't remember any programming language where the input from the user comes in as anything other than a String. So when you get in the input, if it needs to be an integer, there will also need to be some sort of parsing done. This is true for at least Java, ANSI C/C++/C#, and I believe it also to be true for Python and Ruby.

Hope this helps! :sparkles: