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

help to understand the question first

Name.java
// I have setup a java.io.Console object for you named console
public static void main(strings[] args) {
  Console console = System.console();
  String firstName = "vijay";
  console.printf("This is %s\n", firstName);
  console.printf("%s is finding difficulty in learning\n", firstName);
}

1 Answer

vijay, you are making it much harder than it is. All he wants is for you to create a String variable named firstName (as you did), then initialize it to your name (which you also did), and then use the variable in a printf statement (which you did):

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

You don't need to put it in a main method. Also, the console is already there, you don't need to recreate it. As it says: "I have set up a java.io.Console for you.