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 error

String hello = console.printf("Welcome \n\n"); String name = console.readLine("What is your name? \n\n");

        String age = console.readLine("What is your age? \n\n");
        int age = Integer.parseInt(age);
           if  (age <  13) { console.printf("Sorry you are too young");
        System.exit(0); }

It shows illegal start of type if(age<13) { console.printf("Sorry you are too young"); <identifier> expected System.exit(0); } Everything was perfect when i was working in workspace but then i thought of using Netbeans and then got stuck.

1 Answer

michaelcodes
michaelcodes
5,604 Points

Hi there! this is because in the workspace they setup the "boiler plate" code so that you can practice. If you would like to create your programs outside of the workspace you will have to do the following:

Lets say that your program is named "Introduction". And its saved as "Introduction.java"

You would need to set it up as follows (This is the "boiler plate" code of all programs):

public class Introduction {

public static void main(String[] args) {

//Your code goes in here

}
}

Now if we add your code into this it would look like this when finished:

public class Introduction {

public static void main(String[] args) {

     String hello = console.printf("Welcome \n\n"); 
     String name = console.readLine("What is your name? \n\n");
     String age = console.readLine("What is your age? \n\n");
     int age = Integer.parseInt(age);

           if  (age <  13) { 
                 console.printf("Sorry you are too young");
                 System.exit(0); 
           }

}
}

Do not worry about the meaning of that "boiler plate" code yet. It is already done for you in the workspace and is explained in future lessons. If you have any questions let me know!

Take care and happy coding :)