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!
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
I am using eclipse as it is used in my institution and we dont use %s or something for string instead we use the variabl
What is the difference in using a %s for printing a string? we use the variable name instead like : String name ="abcd" System.out.print("My name is " + name);
William LiCourses Plus Student 26,868 Points
You're quite right.
Java gives you different way to combine variable and String together, what you're doing here is called string concatenation, you're concatenating String and variable together using the + sign; another way is called String interpolation, you're inserting variable into a String using the %s formatter.
They both get the job done equally well, usually which one to use is just a matter of style, though I wanna say that if you're inserting lots of variables into a string, using String Interpolation probably makes it a bit easier to figure out how the output String gonna be by looking at the code.