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.

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,040 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,878 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);