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 Reviewing Our Feedback

Kohy Holmes
Kohy Holmes
2,801 Points

Perfecting the Prototype Error

I am getting the following error in the Console when performing this discussion....

TreeStory.java:19: error: illegal start of expression
System.exit(0);
^
TreeStory.java:19: error: ';' expected
System.exit(0);
^

My code is as follows...

import java.io.Console;

public class TreeStory {

public static void main(String[] args) {
    Console console = System.console();
    /*  Some terms:
        noun - Person, place or thing
        verb - An action
        adjective - A description used to modify or describe a noun
        Enter your amazing code here!
    */
  //___Name is a ___adjective___noun___. They are always___adverb____verb___.

  int age = 12;
  if (age < 13) {
    //Insert exit code
    console.printf("Sorry you must be at least 13 to use this program.n\");
    System.exit(0);
   }
  String name = console.readLine("Enter a name:  ");
  String adjective = console.readLine("Enter an adjective:  ");
  String noun = console.readLine("Enter a noun:  ");
  String adverb = console.readLine("Enter an adverb:  ");
  String verb = console.readLine("Enter a verb ending with -ing:   ");
  console.printf("Your TreeStory:\n--------\n");
  console.printf("%s is a %s.", name, adjective, noun);
  console.printf("They are always %s %s.\n", adverb, verb);




}

}

Can anyone spot what I am missing? Thank you -kH

2 Answers

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey there, real simple mistake here it looks like. in your printf statement

console.printf("Sorry you must be at least 13 to use this program.n\");

It should be \n, looks like you just made a typo, in any case it looks like java is a bit confused on what the next step is, let's see if this fixes it.

Try to change it to

console.printf("Sorry you must be at least 13 to use this program.\n");

Let me know if this doesn't help.

Kohy Holmes
Kohy Holmes
2,801 Points

Your suggest worked just fine!. Just curious as to why java didn't call out the error in that line and instead pointed towards the System line?

Thank you-kH

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Good question, error codes are useful, but by no means 100% accurate. Treat them more like guidelines of where (more or less) the error occurred in your program. it reached the forward slash and thought that you just meant to escape the next character, so it had no problem compiling that, however when it saw no end to your String was when it had the heart attack, and where it assumed the error in your program was, so it tried to point your attention to where it could no longer correctly compile the program.