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

getting error

String firstName = "SSSS"; console.printf("firstname:%s", firstName);

I have given like this, I don't know why I am getting error @ "printf".

could you please let me know, where I am doing wrong.

Thanks,

3 Answers

Hi Sunitha,

Task 2 is looking for a specific output: "<YOUR NAME> can code in Java!"

The output that you currently have would be "firstname:SSSS"

It's looking for "SSSS can code in Java!"

Try changing your format string so that it matches what the challenge is expecting.

Hi Jason,

Thanks for quick response. I tried and got it.

You're welcome. Glad you figured it out!

K W
K W
3,736 Points

eye also had problems with this code challenge,***eye did figure it out but what i don't understand is the purpose of >%s< ??? why wouldn't this code work

String firstName = "stuck"; console.printf("firstName" + "can code in Java!");

any help would be appreciated

Hi K W,

That works too but you need to use the variable name and not a string of the variable name. You would also need a space between firstName and can in the output.

console.printf(firstName + " can code in Java!");

I put a space right before "can" so that name and "can" wouldn't run together.

K W
K W
3,736 Points

awesome thank you