Java Java Basics Perfecting the Prototype Parsing Integers

Guys what code decides the warm age? because my console is working perfectly after I delete int age = 12;

Like I say on the question I technically have deleted good amount of lines of codes which I thought were the main part of the warning pg 13, but for some reason the console still responds like if the int age = 12; and if(age<13); were there. did I misinterpret the class of the teacher?

2 Answers

Hi Kerin,

going onwards please remember to paste your code when asking a question, will make answering those much easier.

I assume you have problem making age value based on user input, here is what needs to be done:

  1. Declare String variable and assign it's value to readLine method of Console class.
  2. Parse returned String to Integer value via parseInt method of Integer class.
  3. Use returned Integer in validation process (i.e. if < 13).

Of course I also assumed you have saved all changes and recompiled your classes.

Now, final piece of code should look like this:

String ageAsString = console.readLine("Enter your age: ");
int age = Integer.parseInt(ageAsString);
if (age < 13) {
 //your code here
}

Hope this helps, otherwise just please paste your code.

thank you!

If this helped please remember to mark my answer is accepted - thanks!