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 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.