Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

gaurav jaiswal
813 Pointswhy my code is not running
syntax error is comming
// 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
1,606 PointsHi 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);