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

Monique Maree
PLUS
Monique Maree
Courses Plus Student 1,961 Points

Stuck in a challenge task

Please help me with this question, been stuck on it for a while:

Create a new int variable that is named answer. Store the integer version of answerToLife in it.

Can we see your code?

3 Answers

Szymon Kadłuczka
Szymon Kadłuczka
8,762 Points

I didn't take this course, but I think the correct answer should be:

int answer = Integer.parseInt(answerToLife);
Stephen Bone
Stephen Bone
12,359 Points

Hi Monique

You basically need to convert the string variable to an integer and store it in a variable of int type.

In the previous video Craig discusses using the Integer wrapper with the parseInt method to handle the conversion.

So your code should look as below:

int answer = Integer.parseInt(answerToLife);

Hope it helps!