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
Bhanu Awasthi
1,780 PointsWhy Int age = Integer.parseInt ??
In the program Craig created, he used Int age = Integer.parseInt(ageAsString);
I didnt get this, why he used Integer before parseInt, if he has already mentioned we are dealing with Int (integers) as Int age.
Please advise on this, it could be a silly question though but I am little confuse on this.
2 Answers
Kevin Faust
15,353 PointsHey Bhanu,
parseInt() is a method that belongs to the Integer class. In order to use this method, we must tell our program that we are grabbing it from the Integer class otherwise it wouldn't know where this method is coming from. What this method does is take a string value such as "5" and converts it into 5 (aka an actual number that we can now add/multiply/subtract/etc.). And then we store that number as our int age variable.
Does that make sense?
Kevin
Bhanu Awasthi
1,780 PointsHi Kevin,
I got the point and it does making some sense in my mind now.
Thanks for the clarity, the description given against my question was very simplistic & easy to understand.
Best Regards