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 - Looping Until the Value Passes

I am encountering errors upon running the complier when I have followed the steps to censor words.

TreeStory.java:25: error: illegal start of expression
if (noun.equalsIgnoreCase("dork")) ||
^
TreeStory.java:26: error: ';' expected
(noun.equalsIgnoreCase("jerk")) {
^
TreeStory.java:29: error: ';' expected
} while (noun.equalsIgnoreCase("dork")) || noun.equalsIgnoreCase("jerk");
^
TreeStory.java:37: error: reached end of file while parsing
}
^
4 errors

illegal start of expression usually means looking at preceding lines of code. Can you post your full code?

6 Answers

akiva grobman
akiva grobman
9,160 Points

The line should be like this Console.printf("They are always %s %s. \n", adverb, verb) ;

Thank you Akiva. It worked

akiva grobman
akiva grobman
9,160 Points

From what you have posted it seems like your || are not in the if statement

akiva grobman
akiva grobman
9,160 Points

You seam to be missing a closing bracket fot the if(age <13) And you have an unnecessary bracket on the last console.printf

Thank you. i have added a closing bracket on (age < 13). Removed the bracket you said is unnecessary but i have encountered an error in the console that says

Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
TreeStory.java:38: error: reached end of file while parsing
console.printf("They are always %s %s.\n, adverb, verb");
^
1 error

Aaron Choe
Aaron Choe
1,505 Points

not sure if someone helped you with your recent error. But,

Unedited: console.printf("They are always %s %s.\n, adverb, verb");

the fix should be to add "

Edited: console.printf("They are always %s %s.\n", adverb, verb");

Thank you Kris the full code below:

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__.
  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);
  String name = console.readLine("Enter a name:  ");
  String adjective = console.readLine("Enter an adjective:  ");
  String noun;
  do {  
    String noun = console.readLine("Enter a noun:  ");
      if (noun.equalsIgnoreCase("dork")) ||
         (noun.equalsIgnoreCase("jerk")) {
        console.printf("That language is not allowed. Try again. \n\n");
    }
  } while (noun.equalsIgnoreCase("dork")) || noun.equalsIgnoreCase("jerk"); 

  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 %s.  ", name, adjective, noun);
  console.printf("They are always %s %s.\n, adverb, verb"); {
  }