Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Perfecting the Prototype Censoring Words - Using String Equality

Dhruv Reddy
Dhruv Reddy
269 Points

"Parsing Error" need help I keep getting a parsing error when i run my code. I check and I see nothing.

String ageAsString = console.readLine("How old are you? "); int age = Integer.parseInt(ageAsString); if (age < 13) { //Insert exit Code console.printf("Sorry you must be at least 13 to use this program.\n"); System.exit(0); } //Input String name = console.readLine("Enter your name: "); String adjective = console.readLine("Enter an adjective: "); String noun = console.readLine("Enter a noun: "); if (noun.equalsIgnoreCase("dork")) { console.print("That language is not allowed. Exiting"); System.exit = (0); String adverb = console.readLine("Enter an adverb: "); String verb = console.readLine("Enter a verb ending in -ing: "); //Output
console.printf("%s is a %s %s.", name, adjective, noun); console.printf("They are always %s %s.\n", adverb, verb); }

Thats my code started pretty soon can you find the parsing error?

1 Answer

Simon Coates
Simon Coates
4,963 Points

I made a couple minor modifications (see *):

import java.io.Console;

class Main {
  public static void main(String[] args) {
    Console console = System.console();
    String ageAsString = console.readLine("How old are you? "); 
    int age = Integer.parseInt(ageAsString); 
    if (age < 13) { 
      //Insert exit Code 
      console.printf("Sorry you must be at least 13 to use this program.\n"); 
      System.exit(0); 
    }

    //Input 
    String name = console.readLine("Enter your name: "); 
    String adjective = console.readLine("Enter an adjective: "); 
    String noun = console.readLine("Enter a noun: "); 
    if(noun.equalsIgnoreCase("dork")) {
      console.printf("That language is not allowed. Exiting"); //*
      System.exit(0); //*
    }//*
    String adverb = console.readLine("Enter an adverb: "); 
    String verb = console.readLine("Enter a verb ending in -ing: "); 
    //Output
    console.printf("%s is a %s %s.", name, adjective, noun); 
    console.printf("They are always %s %s.\n", adverb, verb);     
  }
}

I got results of:

How old are you? 17
Enter your name: Dave
Enter an adjective: red
Enter a noun: ball
Enter an adverb: slowly
Enter a verb ending in -ing: ducking
Dave is a red ball.They are always slowly ducking.

How old are you? -8         
Sorry you must be at least 13 to use this program.

How old are you? 34
Enter your name: Eliza
Enter an adjective: orange
Enter a noun: dork
That language is not allowed. Exiting