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 do I call the printf method on the console object and make it write out "<YOUR NAME> can code in Java!"?

Call the printf method on the console object and make it write out "<YOUR NAME> can code in Java!"

Name.java
// I have setup a java.io.Console object for you named console
String firstName = "faddy";
Console.printf("you name can code in java!"); 

1 Answer

Heidi Fryzell
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Heidi Fryzell
Front End Web Development Treehouse Moderator 25,178 Points

Hi Faddy,

Two things I am noticing in your code.

First, when you call the printf method on the console, you should not capitalize the word "console" you will get a syntax error.

Second, they want you to use the variable firstName in place of "your name" when you call the printf method. In order to use the variable you must add a second parameter to the method, "firstName". You also need to use the format specifier "%s" to place the variable in with the text. "%s" is telling Java to put the String variable firstName into the printf statement, s% is like a placeholder for a String variable.

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

If that doesn't make sense, I would watch this video again: https://teamtreehouse.com/library/java-basics/strings-and-variables. The teacher does a better job of explaining it than me. 🙂

Happy Coding! Heidi