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

Seems to be syntax but i am getting the following error message:

I am getting the following error message: ..."Did you forget to pass the firstName parameter to the printf function?"....

I should see the error today ....but I am apparently blind. Your help is appreciated! Thanks, Mark

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
String firstName = "";
String lastName = "";
console.readLine("What is your first name?\n  ", firstName);
console.readLine("What is your last name?\n   ", lastName);
console.printf("First name:%s\n", firstName);

3 Answers

Hi :)

Maybe you get that the error because your String is still empty. I've never tried your way of getting input from the user/keyboard but that is how I would do it:

         // I have imported java.io.Console for you.  It is a variable called console.
String firstName = "";
String lastName = "";
firstName = console.readLine("What is your first name?\n  ");
lastName = console.readLine("What is your last name?\n   ");
console.printf("First name:%s\n", firstName);

Let me know if my answer was helpful, if not, let me also know ;-)

Kourosh Raeen
Kourosh Raeen
23,733 Points

Try this:

// I have imported java.io.Console for you.  It is a variable called console.
String firstName = console.readLine("What is your first name? ");
String lastName = console.readLine("What is your last name? ");
console.printf("First name: %s", firstName);

Hey Patrick and EVERYONE!, Sorry EVERYONE, it as taken me a few days to respond to your help. THANK YOU! My personal life got in the way of my fun. Patrick I believe your suggestion is correct. I realized that the readLine function within the class Console is a correct method of retrieving user input. The issue is I fail to assign a value to the strings correctly. That is lastName = console.readLine("What is your last name?\n "). I had established the instance of a string variable, initialized it to a blank value, but failed to correctly use an assignment statement to transfer the user input into the string variable.

Thank you and everyone else for your help. This is the first time I have asked the community for help and I have to say you folks are great! If would very much welcome if anyone has anymore input.

....By the way how is the job market out there. I have a BSPE degree from UC Berkeley and a BSCS from CalPoly. BUT I have worked in a related field for 10 years, primarily on control systems and embedded logic controllers. No java or the such in that field. So it is a couple months of refresher courses for me. Thanks again, Mark