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 trial

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

How 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");

Name.java
// I have setup a java.io.Console object for you named console
String firstName;
firstName = "Gagan";
printf(firstName + " can code in java");
Teacher Russell
Teacher Russell
16,873 Points

Remember, 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);

1 Answer

Steven Parker
Steven Parker
231,184 Points

Russel 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
Teacher Russell
16,873 Points

Good save, Mr Parker. That's why I'm an English teacher, and only a student of programming:)

console printf(firstName + "can code in Java");

Am upset, losing patient struggling with this , what am missing , what is the correct answer please

Steven Parker
Steven Parker
231,184 Points

Aleksandar, it looks like you have a space between "console" and "printf", but it should be a period instead.