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,599 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,599 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!