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

Problems on converting a string in an integer

I wrote this code and I need to convert the string variable into a int because I want to use an input box, however the compiler is always warming me of bugs on my code. Can you folks help me solve this problem?

I tried to post the code here but It was a mess, so here is the link to my workspace: https://w.trhou.se/cc54jb7hyq >> It's the one named ageRestriction

Note: I'm a beginner ;)

2 Answers

Yeah i see the problem is when you call the console method you have to use scaner this is my code

import java.util.Scanner;

public class Testing {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("What's your age? ");
        String ss = sc.nextLine();

        int age = Integer.parseInt(ss);

        if (age > 12) {
            System.out.println("You are allowed to watch it!");
        } else {
            System.out.println("You are not allowed to watch it because you are under 13 years old");
        }
    }
}

Hum, I understand now but I haven't learned this method yet, I think it's still above my paygrade... Anyways, I will watch some videos and read a bit more about it to try to learn it. Thanks!! As you see, I am still a beginner.

I just test your code in my eclipse and i don't see any problem with your code.

here it isn't workig dude.. I have NO IDEIA of what could have gone wrong. My Eclipse's link > https://www.dropbox.com/s/ctk3kwrirq6fsnj/Untitled.png?dl=0