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

define a string variable FirstName

String, Variables and Formatting

Name.java
// I have setup a java.io.Console object for you named console
Java.io.console;
class Name{
  public static void main(String [] args){
    Console console = new console(Name);
    String FirstName = Samaila;
    console.printf("Hello, is learning %s at treehouse ");
      console.printf("%s is happy learning");
  }
}

3 Answers

Joseph Frazer
Joseph Frazer
5,404 Points

Ah I see. Ok on line 6, you define the variable FirstName as a string. Well strings need to be wrapped around double quotes like so:

String FirstName = "Samaila";

If you want to set FirstName to the variable Samaila, you can do so like the way you did. I hope this helps :)

Also, for lines 7 and 8 you need to add second parameter.

Joseph Frazer
Joseph Frazer
5,404 Points

Yes, the second parameter should be the string you want to put.

console.printf("%s is happy learning", FirstName);

The %s is a placeholder for a string, so after that you put the variable you wish to put there.