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 trialJohn Anselmo
Courses Plus Student 2,281 PointsWhy not just use console.printf(variableName + " rest of sentence.");
Why not just use that instead of ("%s rest of sentence.", variableName); Wouldn't you end up typing all the variable names AND typing a bunch of %s. Couldn't you save a lot of time just typing in the variable name where they're supposed to be?
I did it on the first workspace and it worked.
1 Answer
Steve Hunter
57,712 PointsHi John,
Yes, you can concatenate strings using the +
operator. I think it is considered best practice to use the formatter and placeholders, such as %s
, though. There are many types of placeholder, not just strings. I'm not sure if all of those different data types can be added to a string for output.
Have a look at this to see the different numeric placeholder types that are available. Also, read the Creating Format Strings section of this which may help too.
Steve.