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 Getting Started with Java Strings, Variables, and Formatting

Ronnie Barua
Ronnie Barua
17,665 Points

printf function making me feel like an idiot? can someone please tell me why it doesn't work. Thanks in advance

firstName = "Ronnie"; console.printf("Ronnie");

5 Answers

Sorry Ronnie, I went and looked at the challenge and realized there was more to it.

Part of the problem is that you're not printing your variable but also this challenge is looking for a very specific output.

"<YOUR NAME> can code in Java!"

Ultimately, your output needs to be "Ronnie can code in Java!"

You can use a format string in printf or string concatenation if that's been taught.

Let us know if you still can't figure it out.

Sorry, I jumped the gun.

My instructions on using a format string pertain to task 3.

All you really need to do for task 2 is print the output string with your name hard-coded in it.

In task 3 you'll use the variable.

I hope that clears it up for you.

Ronnie Barua
Ronnie Barua
17,665 Points

Thanks Jason! I missed that. You are very careful I can see. I'll try that.

Ronnie Barua
Ronnie Barua
17,665 Points

Thanks Jason! I did work.

Ronnie

Ronnie Barua
Ronnie Barua
17,665 Points

Thanks Craig! I did try with quote probably that's why it didn't work.

Ronnie

Ronnie Barua
Ronnie Barua
17,665 Points

Sorry! Your trick has failed this time. What else should I try?

Did you use Luke's code as is or make the corrections that Craig Dennis mentioned.?

Eric De Wildt
PLUS
Eric De Wildt
Courses Plus Student 13,077 Points

Your passing in a hard coded string "Ronnie". But you have already declared "Ronnie" in a String variable named firstName. All you have to do is pass in the variable.

No offense but Luke's code is full of syntax errors.

Luke's code should look like this

String firstName = "Luke";
console.printf(firstName);

Notice the differences in syntax.

Edit: Task clarification

My comment pertains to task 3 for task two Jason Annello is correct.

Hi Eric,

Task 2 wants you to use the hard-coded name but with a specific string for output.

Task 3 then has you use the variable in a format string.

Hi Ronnie!

If you are trying to print out what is stored in the variable you can do so as follows.

String firstName = "Luke";
console.printf(firstName);

I don't know if this is what you are looking for! If it isn't reply back and I shall help you further.

-Luke

Craig Dennis
Craig Dennis
Treehouse Teacher

Psst...don't forget the semi-colons and the case of console matters.

Ronnie Barua
Ronnie Barua
17,665 Points

Hi Luke, You are not correct. Unless Treehouse server is falling apart.

Thanks for the reminder Craig! Python has taken the semi-colon out of me!

Also Craig, just out of curiosity... why are you using console.printf on your course instead of System.out.println?

Craig Dennis
Craig Dennis
Treehouse Teacher

It'll do that ;) Swift is helping that cause too.

Swift may also be a contributing factor! In fact now when I go back to Java it feels foreign to add semi-colons at the end of every line.