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 trialJoseph Saika
2,648 Pointshow do i write expressions using a string formatter?
how do i write expressions using a string formatter?
// I have setup a java.io.Console object for you named console
String firstName="joseph";
System.out.printf("<YOUR NAME> can code in Java!");
System.out.printf("can code in Java firstName! %s");
1 Answer
Jonathan Grieve
Treehouse Moderator 91,253 PointsHi Joseph, Welcome to Java :)
I see you've used the original strings as provided by the code challenge.
What you have to do is replace those with a "format specifier" and then pass it in as a comma separated value to printf()
.
So you would try something like this,
String userName = "josephsaika";
printf("Welcome to the website, %s", userName)
You can pass in multiple format specifiers to print. Passing in multiple variables to printf()
and changing the order determines where they appear in the output.
Have a go and let me know if you need further help :)
Joseph Saika
2,648 PointsJoseph Saika
2,648 Points... thanks will come back to you shortly
Joseph Saika
2,648 PointsJoseph Saika
2,648 Pointsi have written it like this System.out.printf("can code in Java! can code in Java firstName! ,%s",() joseph);
its indicating an error on the letter j of joseph
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsBecause in your example you're trying to link the format specifier to the
String firstName =
` variable that you declared. That will then mean that string joseph gets output to the screen.Have a look at my example: