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 Receiving Input

Andrei Oprescu
Andrei Oprescu
9,547 Points

What is wrong with this code?

Can you please tell me what is wrong with this code because it always says in the console "Hello, my name is ..."

 public static void  main(String[] args) {

    Console console = System.console();
    // Welcome to the Introductions program!  Your code goes below here
  String firstName = console.readLine("What is your name?  ");
   console.printf("Hello, my name is %s/n",firstName);
  console.printf("%s is learning how to write Java/n",firstName);
michaelcodes
michaelcodes
5,604 Points

Hi there, I compiled the code and ran it and I didn't have any issues. It prompted me to enter a name and the output was:

"Hello, my name is Mike Mike is learning how to write Java"

Could you please explain what you mean by the "it always says in the console 'Hello, my name is ...'"

Andrei Oprescu
Andrei Oprescu
9,547 Points

As i have done a previous exercise, it told me to make a code that would write in the console "Hello, my name is andrei." Now, even with the code changed, it still says the same thing.

michaelcodes
michaelcodes
5,604 Points

This sounds like an issue with the new code being saved and compiled. Even though the new code was written in your .java file it was not compiled into a .class

Make sure that the new code is saved (file->save or ctrl+s), and then type in the console, replace "filename" with whatever your file is called

javac filename.java

Then run the program as you would normally:

java filename

Let me know if this works, take care and happy coding!