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

James Young
James Young
775 Points

outputting multiple variables

hey guys please if anyone could take a look at my code and let me know where I am messing up I would really appreciate it. Thank you

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");
String pastTenseVerb = console.readLine("Past tense verb:");
console.printf("name: %s",name) really ("Past tense verb: %s",pastTenseVerb) this coding exercise.

2 Answers

Richard Ling
Richard Ling
8,522 Points

Hi James,

The question asks for the output to look like this: name really past tense verb this coding exercise.

I can see how this may be confusing, but it's actually asking for: name really past tense verb this coding exercise. Where the bold items are the variables that you have populated from the user.

The last line should then look like this:

console.printf("%s really %s this coding exercise.", name, pastTenseVerb);

You can write the output string within the quotes, just putting %s in the places that you want your variables to appear, and then comma separate them afterwards. So the first parameter name will replace the first %s and the second parameter pastTenseVerb will replace the second %s.

I hope this makes sense :)

Thanks, Rich

James Young
James Young
775 Points

Hey Rich,

Thank you again for helping me out, it is a little confusing starting out. But having people like you, who help out when can, really makes learning this stuff a little simpler. Thank you for your time!

Best Wishes

Richard Ling
Richard Ling
8,522 Points

No problem James, I'm new to Treehouse, and to a couple of the technologies here too, but it's always good when there's an active community to try help us all along when we need it ;)

Good luck with the rest of the courses!