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,865 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
163,722 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,865 Points

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

Aleksandar Stojanov
Aleksandar Stojanov
114 Points

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
163,722 Points

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