Java Java Basics Getting Started with Java Strings, Variables, and Formatting

Jessi Kitchen
Jessi Kitchen
157 Points

Does %s need to be in parentheses for a string to work properly?

I am trying to code "<your name> can code in Java!"
// I have setup a object for you named console
String firstName = "Jessi"; 
console.printf("%s can code in Java!");

1 Answer

Seth Kroger
Seth Kroger
Treehouse Moderator 56,313 Points

You're close here, but not off in the way you think. When you use %s you are telling the printf method it's a placeholder that there will be a variable after the string to fill that placeholder in with. You put the next variable(s) after the message string separated by commas.

console.printf("%s can code in Java!", firstName);