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 Strings, Variables, and Formatting

Amir Tamim
Amir Tamim
8,597 Points

Could someone please tell me why the code will not go through?

It says illegal expression for the first line.

Name.java
// I have setup a java.io.Console object for you named
public class Name{ 
  public static void main(String args[]){
    String firstName= "Amir"; 
    Console console= System.console();
    console.printf("My name is %s\n", firstName);



  }
}

5 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Amir,

Basically you went way beyond what the challenge is asking for. Instructions are very specific and must be followed explicitly, or the result will be a Bummer!.

If you notice the comment, the console object has been created for you behind the scenes, so for Task 1, you should only have one line of code as the instructions just want you to assign your name to the variable. You do have the correct line of code, you just need to delete everything else and just keep

String firstName= "Amir"; 

Remember, instructions need to be followed exactly. So for Task 2, make sure the string is exactly what the instructions want.

Keep Coding! :) :dizzy:

sandro mirijanashvili
sandro mirijanashvili
2,686 Points

could you please tell me how do you upload this picture here ?

Amir Tamim
Amir Tamim
8,597 Points

Oh got it! Thanks for the help everyone! Much appreciated.

sandro mirijanashvili
sandro mirijanashvili
2,686 Points

import java.io.Console;

// I have setup a java.io.Console object for you named class Name{

public static void main(String args[]){ String firstName= "Amir"; Console console= System.console(); console.printf("My name is %s\n", firstName);

}

}

ps. this code will work. I imported Console and also class Name doesn't need to be public.

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Actually sandro mirijanashvili,

The above code is not correct and will produce a Compiler Error in the challenge. Please see my answer to Amir below.

sandro mirijanashvili
sandro mirijanashvili
2,686 Points

actually i don't have membership and can't see it in treehouse I wrote in notepad++ and got a correct output .

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

It's not a picture. It is a code block inserted using Markdown. You can refer to the Markdown CheatSheet above the "Post Comment" button, or take the new Treehouse course on Markdown Basics. Code should always been formatted with markdown when posting to the Community, otherwise it is very unreadable.