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

Output for a task challenge on String concept.

Output a sentence that takes both the name and past tense verb using a single statement. It should look like this: name really past tense verb this coding exercise.

Multiple.java
// I've imported java.io.Console for you.  It is stored in a variable called console for you.
String name = console.readLine(" *Mirza* ");
String pastTenseVerb = console.readLine("*was doing great in*");
console.printf("*Mirza* really *was doing great in* this coding exercise %s%s\n",name,pastTenseVerb);

3 Answers

Hey MIrza,

First, for your name variable, you should have a more appropriate prompt for the user. For example, 'Enter your name: '. Same goes for your pastTenseVerb variable.

Your issue with this challenge is your print statement. Do you remember how to use %s? If not, I would suggest re-watching the video.

However, if you're stuck, consider the following:

// Prompt user for their favorite game and assign input to favoriteGame
String favoriteGame = console.readLine("Enter your favorite Game:  ");
// Use the format method to print the user's favorite game
console.printf("%s is my favorite game.", favoriteGame);

Hey Jacob, thanks for your help mate. I know how to use %s, but did you check the print statement task it should come in an asterisk, that is where I got stuck anyhow, I'll use this as an example and I'll try and if in even worst case if it doesn't work I'll pass my comments...

Ah, I see where you got confused. The asterisks were meant to be an indication as to where your name and pastTenseVerb variables should be in your final print statement. I can see how that can be misleading to the user.

If that doesn't make since, check out the following:

You are a *age* year old *gender*.

String age = console.readLine("What is your age? ");
String gender = console.readLine("Are you male or female? ");
console.printf("You are a %s year old %s.", age, gender);

Thanks for your help, I cracked it. You know, I thought asterisk has to be in a printf statement.

Great to hear!