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 trialJay Penerian
2,532 PointsHelp 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);
1 Answer
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 PointsHi 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);
Jay Penerian
2,532 PointsJay Penerian
2,532 PointsThink I figured this one out myself. Looks like I forgot to add the console.readLine(%s); line under the lastName String.