Java Java Basics Getting Started with Java IO

Help With printing First and Last name

Can someone please tell me where I went wrong with my code here. I am pretty sure I did it properly. The exercise directions state: Using the console's printf method, display a message that says, "Last name: " followed by the last name that the user has entered. I get an error that asked if I passed the parameter for lastName.
// I have imported for you.  It is a variable called console.
String firstName = console.readLine("Jay");
String lastName = console.readLine("Penerian");
console.printf("First name: %s", firstName);
console.printf("Last name: %s",  lastName);

Think I figured this one out myself. Looks like I forgot to add the console.readLine(%s); line under the lastName String.

1 Answer

Tonnie Fanadez
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,786 Points

Hi Jay Penerian

I see you have already figured out how to collect input from the user using *console.readLine () * method, you're doing great!!

So the first 2 lines of code should look like this:

String firstName = console.readLine("Jay");
String lastName = console.readLine("Penerian");

The only method you need you may be getting wrong is console.printf() **. This method is for printing out or displaying the output to the user. console.printf() method first argument takes a specified string format which should be inside "" quote marks. Here you can use formatting specifiers(e.g. %s, %d, \n ) as place holder for the variables. The second argument takes the variables - in this case, variables are **name and pastTenseVerb.

Please see this code snippet on how I wrote the third challenge - I used %s as placeholders for the String variables and and after the coma I included name and pastTenseVerb for the second argument separated by a coma.

console.printf("%s really %s this coding exercise", name, pastTenseVerb);