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 trialchase singhofen
3,811 Pointspass the `firstName` parameter to the printf function? it also says i need to use %s i have used both but no success
pass the firstName
parameter to the printf function?
it also says i need to use %s i have used both but no success
// I have imported java.io.Console for you. It is a variable called console.
String firstName = "chase";
console.readLine("chase");
String lastName = "singhofen";
console.readLine("singhofen");
console.printf(" %s First Name: firstName");
1 Answer
Chris Adamson
132,143 PointsThe intermediate String aren't necessary, you can simply read into the variables with the readLine, and then use the firstName in the printf. The firstName is included as a parameter to the printf method, it's not part of the String:
// I have imported java.io.Console for you. It is a variable called console.
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine();
String lastName = console.readLine();
console.printf("First name: %s", firstName);