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 Using your New Tools Multiple Format Strings

how to put the spaces to frame this statement :`__name__ really __pastTenseVerb__` described above

The output is not clear as to what to get on the screen

Multiple.java
// I've imported java.io.Console for you.  It is stored in a variable called console for you.
String name = console.readLine("Name:%s");
String pastTenseVerb = console.readLine("Past Tense Verb:%t");
console.printf("%s",name);
console.printf("really");
console.printf("%t",pastTenseVerb);
console.printf("this coding exercise");

1 Answer

Chase Marchione
Chase Marchione
155,055 Points

Hi Aditi,

  • The challenge instructions want us to stick to only one print statement. Thankfully, this can be done!
  • Java uses %s to specify that the type of the variable to print is a string, and not some other data type. Fortunately, we can use %s multiple times in a single statement, because Java can tell the order of the variables to print from the order of the arguments in our statement.
  • When printing a statement like this one, we want to make sure that spaces are properly printed in, so that the statement 'reads like this', rather than 'readslikethis'.
// I've imported java.io.Console for you.  It is stored in a variable called console for you.
String name = console.readLine("Name:");
String pastTenseVerb = console.readLine("Past Tense Verb:");
console.printf("%s really %s this coding exercise.", name, pastTenseVerb);

Hope this helps!