Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Getting Started with Java Strings and Variables

My code looks exactly the same but I'm experiencing an error. Any ideas why?

my code:

import java.io.Console;

public class Introductions {

    public static void main(String[] args) {
        Console console = System.console();
        // Welcome to the Introductions program!  Your code goes below here
        String firstName = "Whitty";
        console.printf("Hello, my name is %s\n, firstName");
        console.printf("%s is learning how to write java\n, firstName");


my console output:

Exception in thread "main" java.util.MissingFormatArgumentException : Format specifier '%s'
at java.util.Formatter.format(Formatter.java:2519)
at java.util.Formatter.format(Formatter.java:2455)
at java.io.Console.format(Console.java:170)
at java.io.Console.printf(Console.java:209)
at Introductions.main(Introductions.java:9)

Any explanation?

Leen Leenaerts
Leen Leenaerts
1,096 Points

As far as I know it should be

"Hello, my name is %s\n", firstName

instead of

"Hello, my name is %s\n, firstName"

I am not sure if this would solve it

1 Answer

Your code is almost perfect apart from your printf line! The ", firstName" of that needs to be outside of the quotation marks. Once you have changed this all your errors should be gone!

Thanks so much its working now.

Leen Leenaerts
Leen Leenaerts
1,096 Points

that's what i commented before :)

Yeah, thank you too. This is unrelated, but its there C# on this website. I've been looking all over and can't find it. That's the language I have to learn, but I've just been doing java because I hear they are very similar.

Hi Pierce!

There currently aren't any C# lessons here on Treehouse but they will most likely be coming at some point in the future. You have heard right, as well, Java does have some similarities with Java. However, if you are learning C# for a job I would recommend that you just try and learn that.