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

Printf ("My name is %s", firstName);

I keep getting compile error

Name.java
// I have setup a java.io.Console object for you named console
String firstName="MOHAMMED";
Printf ("My name is %S", firstName);

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Mohamed,

Try something like...

console.printf("your message %s", firstName)"

There a couple of syntax errors making the compiler throw some errrors :-)

andren
andren
28,558 Points

Ironically enough your example contains a syntax error as well :smile:.

andren
andren
28,558 Points

The printf method belongs to the console object, so you have to call it using console.printf() not simply printf(). Also capitalization differences matter. Printf and printf are considered to be entirely different words as far as Java is concerned, so you have to make sure to type it with the proper case.

You also have to use the exact string the task instructs you to use. The task asks you to print out <YOUR NAME> can code in Java! not My name is <YOUR NAME>. So you have to change the string you are printing out to match that sentence.