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

I have been trying to compile my code but every time i get an error "ill legal start" though everything seems alright.

Please find attached my code.

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


Public class IO{


  public static void main(String[] args){
 onsole console =   System.console();
  String firstName = console.readLine("Whats is your name");
  console.printf("Hello,myname is %S \n"+firstName);
}
}

1 Answer

Lukas Baumgartner
Lukas Baumgartner
14,817 Points

Have you imported

import java.io.Console;

at the top of your code?

On line 1:

Public class IO

the P at the beginning should be a p

Also on line 3 where it says:

onsole console =   System.console();

there is a C missing.

And on the last line

console.printf("Hello,myname is %S \n"+firstName);

it should be

console.printf("Hello, my name is %s %n", firstName);

Try to be more concentrated when you are writing your code. Those are pretty basic mistakes that you can find yourself if you use the help of google for example, I myself learn more if i try to correct my own mistakes :)