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 trial

Java Java Basics Getting Started with Java IO

Using the console's printf method, display a message that says, "First name: ", followed by the first name.

Where am I going wrong ?

IO.java
// 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
Simon Coates
28,694 Points

ok, 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);

Haha.. treehouse has changed the questions.. Wasted soo much of time. Thanks a lot Simon.

Simon Coates
Simon Coates
28,694 Points

try:

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.

Simon, 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..

But with my code the error is : Did you forget to pass the firstName parameter to the printf function?