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

javier montoya
javier montoya
51 Points

Java Console printf

Its asking for me to put in the code for the first name and i did and even watched the video again but i keep getting an error

IO.java
String firstName= console.readLine("javier");
String lastName= console.readLine("montoya");
console.printf=("First name");

2 Answers

Lukas Baumgartner
Lukas Baumgartner
14,817 Points

I think the task is to print out a Name you entered when prompted by the program. It should look something like this:

String firstName = console.readLine("Enter your first name: ");
String lastName = console.readLine("Enter your last name: ");
console.printf = ("First Name: %s %n Last Name %s %n",firstName, lastName);

So. What did I do here? The first two lines read the userinput. The user has to input his first an last name into the console. This input is then stored in the variables firstName and lastName. the third line is where we concat the string and put it out in the console to read. %s is a placeholder for the variables we want to show. You have to be carefull to place the variables in the correct order after the quotationmarks! %n is a formatting tool. Just try it out to see what it does ;)

I hope this makes it clearer now!

Christopher Lebbano
Christopher Lebbano
15,338 Points

Try using no quotation marks and using firstName instead of Firstname