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 trialTamara McDiarmid
4,351 Pointsprint firstName plus can code in java to console
I've typed console.printf(firstName "can code in Java!"); but I'm getting a cummer compiler error.
// I have setup a java.io.Console object for you named console
String firstName= "tamara";
console.printf(firstName %s, "can code in Java!");
2 Answers
Daniel Szepanski
Courses Plus Student 5,098 PointsHi, you have to turn around your code like this, it should work.
// I have setup a java.io.Console object for you named console
String firstName= "tamara";
console.printf("%s can code in Java!" , firstName);
Felix Sonnenholzer
14,654 PointsLike Daniel said it works if you change the order.
The important thing is, that %s
is part of the String you want to print.
%s
is just a placeholder for the additional parameter you provide.
You can also use %s
multiple times, but you have to provide enough arguments.
String firstName = "Felix";
String lastName = "Sonnenholzer";
console.printf("My first name is %s and my last name is %s", firstName, lastName);
The first %s
gets replaced by the first parameter and the second %s
by the second and so on.