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
Jennifer Nordell
Treehouse Staff

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: