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.


daniel zaragoza
daniel zaragoza
1,843 Points

i keep getting illegal start of expression error. Help

I'm trying to create a list of words i want to censor but i keep getting the "illegal start of expression " error. Here is the code below.

import java .io.Console;

public class HelloWorld{

 public static void main(String []args){
    Console console = System.console();

    String user = console.readLine(" Enter age");
    int age = Integer.parseInt(user);
        if(age < 18 ){
        console.printf("Sorry you're too young. Exiting!");
        String [] myList ={"stupid", "dummy", "douchebag", "dork", "jerk", "idiot", "nerd"};
          String name =;
          boolean inValid =; 
           name = console.readLine("Enter Name");
           inValid = (name.equalsIgnoreCase(myList));


          console.printf("Sorry that language is not allowed. Try again.  \n\n" );

        } while(inValid);

1 Answer

One problem is that you can't do this:

          String name =;
          boolean inValid =; 

I suggest you do this instead:

          String name;
          boolean inValid = true; 

That is, leave name uninitialized, as you provide a value later. But initialize inValid to true, as you will test and change it to false if the name is invalid.

Next, the compiler doesn't like this:

inValid = (name.equalsIgnoreCase(myList));

because myList is an array, but the equalsIgnoreCase() method takes a String. What you probably intended to do was loop through the array and compare name to each name in the array. But you are not doing that here.