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

Melody P
Melody P
801 Points

How do you output multiple variables?

Am I understanding the question wrong for this task? I didn't learn this in the course yet but I assume the challenge just wants you to learn by some trial and error method but I'm stumped.

Multiple.java
// 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("I can't think of a question in past tense?  ");
console.printf("%s really %s this coding exercise", firstName, pastTenseVerb);

2 Answers

andren
andren
28,558 Points

Your code is logically correct, you just have a typo. You store the first name is a variable called "name" but then use the word "firstName" when trying to print it out in the printf statement, since "firstName" is not actually a variable your code crashes. Fix that variable name and your code will run fine.

Melody P
Melody P
801 Points

Thank you so much!

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

You're doing it right, you're just trying to put in a variable firstName when your name variable is just called name. You can click on the Preview button to see the details of the compiler error.

JavaTester.java:118: error: cannot find symbol
console.printf("%s really %s this coding exercise", firstName, pastTenseVerb);
                                                    ^
  symbol:   variable firstName
  location: class JavaTester
1 error