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 trialGianni Ramirez
326 Pointsim totally stumped
Using the console's printf method, display a message that says, "First name: ", followed by the first name that the user has entered. I cant figure it out
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("firstName");
String lastName = console.readLine("lastName");
String firstName = "Gianni";
console.printf("firstName",Gianni);
1 Answer
Dave Harker
Courses Plus Student 15,510 PointsJust had a quick look at the challenge, and then at your code....
You've nailed it for the firstName and lastName declaration and assignment using readLine();
Nice work there
However, the next line you're trying to declare and assign firstName again which is already handled in the first line of your code. You can safely delete the line String firstName = "Gianni";
When the challenge runs I imagine it is feeding in data that your code (the readLine) is picking up and assigning to those variables for you (testing). So just let the system handle that.
You last line of code, you almost had it!! What they are looking for here is to output the message along with the content of the string variable firstName (which as we know is already handled via the readLine in your first code line there). You can use the string placeholder %s in your string output followed by the variable name after the string that you want to replace it with. Hopefully this example explains what I mean.
String animal1 = "fox";
String animal2 = "dog";
console.printf("The quick brown %s jumped over the lazy %s", animal1, animal2);
I don't want to just give you the answer because you'll learn more if you figure it out. Hopefully the information above is enough to get your there :)
Keep going - you're almost there!!
Kind regards,
Dave