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 Getting Started with Java IO

Illegal start of expression in import java.io.Console; and with my public class Introduction , help!

just illegal expression in import java.io.console; and public classs Introduction {

IO.java
import java.io.Console;

public class Introduction {

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

      String firstName = console.readLine("What is your name? ");
      //CamelCasing
      console.printf("Hello, my name is %s\n", firstName);
      console.printf("%s is learning how to write Java\n", firstName);
    }
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Take a look at the very first comment of the code:

// I have imported java.io.Console for you.  It is a variable called console.

You cannot import it because it's already been imported. These challenges are a little special and require that you do exactly what they say and nothing more. The challenge does not ask you to define a class nor make the main method.

Step 1 should only require one line of code, which you have:

String firstName = console.readLine("What is your name? ");

:bulb: Try not to do anything the challenge doesn't explicitly ask for. Even if functional outside the challenge, it can cause the challenge to fail.

Hope this helps! :sparkles: