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

Call the print f method

Hey! I'm currently taking the Java Basics course and one of the exercises asks the following: //Call the printf method on the console object and make it write out "<YOUR NAME> can code in Java!" The error I'm getting is: Bummer: There is a compiler error. Please click on preview to view your syntax errors! // I have setup a java.io.Console object for you named console //Console console = System.console(); import java.util.*; String firstName = "Mada"; console.printf("%s, firstName can code in JAVA!");

Any ideas what it's expecting me to do? I tried without the Console console... and without importing the java.util.*

Name.java
//Hey. I'm currently doing the java basics course and running into some issues with this exercies:
//Call the printf method on the console object and make it write out "<YOUR NAME> can code in Java!"
//Bummer: There is a compiler error. Please click on preview to view your syntax errors!
// I have setup a java.io.Console object for you named console
//Console console = System.console();
import java.util.*;
String firstName = "Mada";
console.printf("%s, firstName can code in JAVA!");
Athanasios Kourtzis
Athanasios Kourtzis
6,437 Points

Hi, the way you wrote the printf method, firstName is part of the string. What you should do is use firstName outside of the quotation marks. For example

String name = "Mada"; console.printf("Hello, my name is %s", name);

Raquez Lockhart
Raquez Lockhart
403 Points

String firstName = "Raquez"; console.printf("%s",firstName);

//trying to do the java basic keep giving error I don't know what i am doing wrong

1 Answer

Tsenko Aleksiev
Tsenko Aleksiev
3,819 Points

You got it wrong. The way you use it is like this: ā€œ%placeholder can code in JAVA!ā€, variableName I placed placeholder because after the ā€œ%ā€ sign you can use s for String, d for digit and f for floating number. Hope I helped