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 trialAtul Varma
4,285 PointsUsing the console's printf method, display a message that says, "First name: ", followed by the first name.
Where am I going wrong ?
// I have imported java.io.Console for you. It is a variable called console.
String firstName = "Atul";
String lastName = "Varma";
console.readLine("%s", firstName);
console.readLine("%s", lastName);
console.printf("First Name:%s", firstName);
2 Answers
Simon Coates
28,694 Pointsok, i'm not sure what's going on, but I just passed the challenge with:
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("What is the first name?");
String lastName = console.readLine("What is the last name?");
console.printf("First Name:%s", firstName);
console.printf("Last Name:%s", lastName);
Simon Coates
28,694 Pointstry:
String firstName = console.readLine("What is the first name?");
console.printf("First Name:%s", firstName);
You can see https://docs.oracle.com/javase/7/docs/api/java/io/Console.html for an explanation of methods on the Console class. The important thing is the arguments taken and the values returned. If you have further doubts, I can try and explain things in more depth.
Atul Varma
4,285 PointsSimon, its still giving error as--"There is a compiler error. Please click on preview to view your syntax errors!".... And the code is same as above..
Atul Varma
4,285 PointsBut with my code the error is : Did you forget to pass the firstName
parameter to the printf function?
Atul Varma
4,285 PointsAtul Varma
4,285 PointsHaha.. treehouse has changed the questions.. Wasted soo much of time. Thanks a lot Simon.