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

Hank Deeter
Hank Deeter
75 Points

Im not sure what I'm doing wrong, and when Im supposed to apply %s

What am I doing wrong?

IO.java
// I have imported java.io.Console for you.  It is a variable called console.
         String firstName = "Hank";
        String lastName = "Deeter";
   console.readLine("firstName");
   console.readLine("lastName");
   console.printf("%sFirst Name:", firstName);

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Hank,

welcome to treehouse ... you will love it here :)

Let me explain the challenge a little bit ... and I had to modify your code a little bit

// I have imported java.io.Console for you.  It is a variable called console. 
String firstName;
String lastName;

// here you declare two String variables "firstName" and "lastName"
// after Declaration you can initialise a value to every of this Strings : "Hank" and "Dieter"
// but you dont need it to do in this challenge this way

firstName =  console.readLine("Hank");
lastName = console.readLine("Deeter");
// for value initialisation we can use the console class and its method readLine
// this method stores a String value inside the parenthesis into a String variable like firstName/lastName
// before the two lines abowe you had only two Stings with a "null" default value
// this null value is set automaticly by Java after Declaration if you have no = sign

console.printf("First Name is: %s", firstName);
//here we come to your question :)
// %s is a String formater ... where you put it using the console.prinf funtion there will be your String (s after the % sighn)
// %d is a formatter for decimal for example

Let me know if you need more help

Grigorij