Jay Penerian1,824 Points
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 java.io.Console for you. It is a variable called console. String firstName = console.readLine("Jay"); console.readLine("%s"); String lastName = console.readLine("Penerian"); console.printf("First name: %s", firstName); console.printf("Last name: %s", lastName);
Tonnie FanadezUX Design Techdegree Graduate 22,154 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);