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

What am I missing here?

I keep getting an error, No clue what I missing. I fairly new to this...

Name.java
// I have setup a java.io.Console object for you named console
String firstName = "Mike";
consel.printf("%s can code in Java\n,");

1 Answer

andren
andren
28,558 Points

There are a couple of issues with your code:

  1. You have a typo in your second line, consel should be console.

  2. When you use the %s placeholder with the printf method you are telling printf to replace that placeholder with some variable. The thing is that you have to specify what variable you want to insert into the string. You do that by placing a comma outside the string and then writing the name of the variable.

  3. These challenges tend to be very picky about strings, the string you write usually has to match the example string exactly to the dot. In your string you place a line break and a comma at the end which is not present in the example string. Which will cause the code checker to mark your code as invalid.

If you fix all of those issues you end up with this code:

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

Which will pass the test.