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 trialGagandeep Singh
Courses Plus Student 468 PointsHow to call the printf method?
Call the printf method on the console object and make it write out "<YOUR NAME> can code in Java!"
My answer: String firstName = "Gagan"; printf(firstName + " can code in java");
// I have setup a java.io.Console object for you named console
String firstName;
firstName = "Gagan";
printf(firstName + " can code in java");
1 Answer
Steven Parker
231,269 PointsRussel makes a good point, but the object created for you by the challenge is "console", with a lower-case "c". This is an important difference since Java is case-sensitive:
console.printf(firstName + " can code in java");
Also, your concatenation will work just fine though the token substitution used in Russel's example is a more conventional use of printf.
Teacher Russell
16,873 PointsGood save, Mr Parker. That's why I'm an English teacher, and only a student of programming:)
Aleksandar Stojanov
114 Pointsconsole printf(firstName + "can code in Java");
Am upset, losing patient struggling with this , what am missing , what is the correct answer please
Steven Parker
231,269 PointsAleksandar, it looks like you have a space between "console" and "printf", but it should be a period instead.
Teacher Russell
16,873 PointsTeacher Russell
16,873 PointsRemember, we're calling it on the Console object, we have to use Console.printf(); Then we can say, Console.printf("%s can code in java", firstName);