Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
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? "); console.printf("name"); String pastTenseVerb =console.readLine("pastTenseVerb"); console.printf("%s", really , "pastTenseVerb" , "this", coding exercise);
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
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
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)
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! :)