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 trialkimberli Broadus
3,197 PointsUsing the console's printf method, display a message that says, "First name: ", followed by the first name that the user
How should this be written
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("Kimberli");
String lastName = console.readLine("Broadus");
String firstName = console.printf("Kimberli");
2 Answers
Chase Marchione
155,055 PointsHi Kimberli,
1) There's no need to declare firstName again. In fact, the Java compiler won't allow the variable to be declared more than once.
2) You'll need to use a placeholder, known as a formatter, to follow the printf method's syntax rules for telling the Java compiler that you have a string variable you want to print out. You'll want to use the %s string formatter, and after a comma, state which string variable you want to print out.
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("Kimberli");
String lastName = console.readLine("Broadus");
console.printf("First name: %s", firstName);
You'll be writing something similar to that last line for step 4.
Hope this helps!
kimberli Broadus
3,197 PointsThank you, CJ
Rohit Tolawat
8,277 PointsRohit Tolawat
8,277 PointsString firstName = console.readLine("Enter your first name:"); console.printf("First Name: %s \n",firstName);
/* Do the above and I think your issue would be solved */