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 trialSamir Swarup
39 PointsWhy compiler error for String program which I have written as same program is working fine in your workspace as Name.jav
Same file is there in workspace which is working fine.
// I have setup a java.io.Console object for you named console
//import java.io.Console;
public class Name {
public static void main(String[] args) {
Console console = System.console();
String firstName = "Samir";
console.printf("My Name is %s \n",firstName);
}
}
2 Answers
Patrik Horváth
11,110 Pointsbecause this is JAVA not C or C++ your syntax looks like on C++ watch videos again for getting to know JAVA syntax :)
C++ syntax :
console.printf("My Name is %s \n",firstName);
Java Syntax :
console.printf("My Name is " + firstName);
Samir Swarup
39 PointsHi Patrik,
Thanks for your answer but in Java we do also write : System.out.println("My Name is " + firstName);
But here in the video the example which they show is like this only: console.printf("My Name is %s \n",firstName);
Don't know how in video they are able to run if it is wrong here.
Samir Swarup