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 named firstName that stores your name. Set the value to your name.

Please help me. Am getting errors.

Name.java
import java.io.Console;

public class Myname{

  public static void main(String args[])
  {
    String myFirstName = "vinay";
    Console console = system.console();
      console.printf("My name is" %s",myFirstName);
  }

3 Answers

Andrey Serebryanskiy
Andrey Serebryanskiy
5,756 Points

when using console.printf() you should put placeholders like %s for strings or %d for digits inside the quotes. For instance:

String myName = "Andrey";
console.printf("My name is %s", myName);   // will output My name is Andrey
Eugenio Villarreal
Eugenio Villarreal
8,041 Points

Hello, what errors are you getting?

Your variable is called "myFirstName" and the challenge is asking for "firstName" ... might be part of the issue.

Also, and more important... your console.printf has an extra (")

Joseph Sworyk
Joseph Sworyk
7,879 Points

Error with the quotation marks, you have an unclosed quotation mark after the %s... Should look like this:

console.printf("My name is %s",myFirstName);