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 trialPauliina K
1,973 Pointsfirstname
I don't understand how to write the "first name that the user has entered". I tried using %s, but that got an error as it's not declared anywhere. I then tried using just "firstName", but that gave me an error too. I also tried just putting in my name. What am I missing?
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("What's your name?");
String lastName = console.readLine("What's your last name?");
console.printf("First name: ", firstname);
Pauliina K
1,973 PointsThank you Ethan! That makes sense.
1 Answer
Ethan Lane
876 PointsHi Pauliina,
In your code you need to use the %s because you are using the "printf" method where the 'f' stands for format. This allows you to use things such as %s. Using %s represents that a string will be placed where you placed the %s. In this case we want it to display what the user has entered for his/her first name. The problem you are having is you do not have %s in your print method, and if you were to place it you are calling the wrong variable, "firstname", which has not been declared. You declared the variable as firstName using the proper camel casing style. So your code should look like this.
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("What's your name?");
String lastName = console.readLine("What's your last name?");
console.printf("First name: %s", firstName);
Mod Note - Changed from comment to answer so that it may be voted on or marked as best answer.
Pauliina K
1,973 PointsPauliina K
1,973 PointsThis is the error I get:
JavaTester.java:119: error: cannot find symbol console.printf("First name: ", firstname); ^ symbol: variable firstname location: class JavaTester 1 error
And I sometimes get this:
Bummer! Ensure you put the string formatter
%s
in your format string