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

Hello on setting up variable

I just need to find out why my code isnt't working right.

Name.java
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 = "Roberto";
      console.printf("hello, my name is /n", firstname);
  }
}

2 Answers

Roberto, you did way too much work. They didn't want a program!

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

Note, Java is case-sensitive, so firstname and firstName are different. "%s" is a format specifier, and will be replaced by the value of the firstName variable when the String is printed.

You had the wrong symbol: the \n is a new line character and the %s is basically a placeholder for a variable. It should look like this:

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 = "Roberto";
      console.printf("hello, my name is %s", firstName);
  }
}