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

why my code is not running

syntax error is comming

Name.java
// I have setup a java.io.Console object for you named console

public class jar{


  public static  void main(String [] args){

     Scanner sc=new Scanner(System.in);
    String firstName="Gaurav";

    System.out.println("hello my name is "+firstName);

  }



}

1 Answer

Gabe Olesen
Gabe Olesen
1,606 Points

Hi Gaurav,

For this specific example the challenge wants you to use the console class which has been imported for you already;

// I have setup a java.io.Console object for you named console

For this challenge you don't need the Scanner class, however for future reference if you're going to use Scanner like Console you have to import from the java.util package like so;

import java.util.Scanner; 

public class jar{


  public static  void main(String [] args){

     Scanner sc = new Scanner(System.in);

    //If you would like to use the Scanner class in the future it would some this;
    System.out.print("Oh hey! Welcome to Java! Enter in your name here:  "); 
    String name = sc.nextLine(); 
    System.out.println("Hello " + name + " have a great day!"); 

  }
}

Back to the challenge, the challenge wants you to use the console.printf method and the %s String formatter so if you're able to try this;

// I have setup a java.io.Console object for you named console
String firstName = "Gaurav";
console.printf("%s can code in Java!", firstName);