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 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
8,377 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