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

whats wrong with this code, its now confusing, please help i'm now stuck , clueless now

cant get it right any how

// I've imported java.io.Console for you.  It is stored in a variable called console for you.
String name = console.readLine("what is your name?  ");
String pastTenseVerb =console.readLine("pastTenseVerb");
console.printf("%s",  really  , "pastTenseVerb"  , "this", coding exercise);

1 Answer

Hi Ted. To add to Alastair Cooper's answer to you in your other post here, what the exercise expects here, is this sentence: "name really past tense verb this coding exercise.", where name and past tense verb are placeholders (replacements) for the name and pastTenseVerb variables we declared before. It's a bit like saying "X really Y this coding exercise.", where X is the name variable and Y is the pastTenseVariable.

When formatting a string, we do not use X and Y for strings in Java, but %s, so we'll write:

"%s really %s this coding exercise"

where %s replaces a string each time.

We want the first %s to be the name string variable we declared earlier, and the second %s the pastTenseVerbe variable. In order to do that, we just add these 2 variables that will replace the 2 %s after our formatted string (the string with both %s), in order, like this:

("%s really %s this coding exercise", name, pastTenseVerb)

So name will replace the first %s, and pastTenseVerb the second.

Now you have all the elements to complete the exercise. You can do it! Just remove your second line of code:


as it is not needed here.

Good luck! :)

thank you so much it only needed the removal of the previous console.priintf("name"); and console.printf("pastTenseVerb");

Great! I'm glad you sorted it out :)