Java Java Basics Getting Started with Java IO

Salem Osi
Salem Osi
1,928 Points

No idea what I'm doing wrong

I'm pretty sure I got everything right, but it's still giving me syntax errors, does anybody know what I'm doing wrong?
// I have imported for you.  It is a variable called console.
String firstName = "Tyrone"; 
console.readLine (firstName); 
  String lastName = "West";
console.readLine (lastName); 
  console.printf ("First name:%s", firstName); 

1 Answer

Tonnie Fanadez
Tonnie Fanadez
UX Design Techdegree Graduate 22,777 Points

Hi Salem Osi

Thanks for your question.

String firstName = "Tyrone"; 

Your first line of code is declaring a String and forcing it to be "Tyrone" which should not be the case. Remember the challenge requires you to collect input from the user and not to set a String to a value.

The way to get input from the user is to use the console's method readLine() to prompt for the name. readLine method takes in the message which will prompt the user.T he code goes like this:

//getting feedback from the user using console.readLine() method
String firstName =console.readLine ("what is your first name?");
String lastName =console.readLine ("what is your first name?");

When it comes to print out the info you can use the console's printf method as per the below code:

console.printf("First name: %s", firstName);
console.printf("Last name: %s", lastName);

Happy coding