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 trialIzhar Ashraf
762 PointsUsing the console's printf method, display a message that says, "First name: ", followed by the first name that the user
what will be the answer for this question?
// I have imported java.io.Console for you. It is a variable called console
String firstName = console.readLine("Enter your first name: ");
String lastName = console.readLine("Enter your last Name:");
console.printf(firstName);
1 Answer
Naveed Sarwar
Courses Plus Student 1,081 PointsDear, Izhar.
You need to know that printf method is used when we have to specify the format of the output data. In this case, as required by the challenge, we have to specify the output such as: First Name: Izhar
It should be like this:
// I have imported java.io.Console for you. It is a variable called console
String firstName = console.readLine("Enter your first name: ");
String lastName = console.readLine("Enter your last Name:");
console.printf("First Name: %s", firstName);
//%s means that String value of firstName is going to replace %s.
One more thing, you can also directly the print the value of a variable using println(firstName);
[MOD - edited code block]
Izhar Ashraf
762 PointsThank you very much sir it worked for me.
Raymer Ramos
7,683 PointsRaymer Ramos
7,683 Pointsconsole.printf("First name: %s" , firstName);