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

Java Basic

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.

I got stuck. Can you guys please help me☺?

// 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("Enter a verb here:  ");
console.printf("%s really %s this coding excercise", name, adjective);

2 Answers

Gaspar Santiago
Gaspar Santiago
3,377 Points

If you were declaring the variable name, you wouldn't declare it with the sentence "What is your name?". You'd declare it with an actual name, which means in this case, "what is your name" should be on a separate line: System.out.println("What is your name?"); Declare the String variable name like so: String name = ""; < Leave it empty

Then when you run the program, console.readline() will take in whatever name you type in. The parameter for console.readLine() will be the String variable "name" which you will put in the parenthesis of console.readLine as its parameter. console.readLine(name); To check for this you can run: System.out.println("You entered " + name); Then the name you entered will be verified.

Apply the same logic for pastTenseVerb =D

Good Luck!

Ryan Custodio
Ryan Custodio
5,626 Points

Hi. I'm just new here and I also got stuck on this but I manage to come up with the right answer.

String name = console.readLine("%s");

String pastTenseVerb = console.readLine("%s");

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

I hope it helps.