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 trialGary O'Neill
51 PointsI have created my class as below public class Name{ Why am I getting error message saying this is incorrect?
Please let me know Thanks
// I have setup a java.io.Console object for you named con
public class Name{
public static void main(String args[]){
String firstName ="Gary";
}
{
Console console = System.console();
console.printf("Gary, can code in Java!");
}
}
3 Answers
Gary O'Neill
51 PointsHi Jeff James,
no still getting the same error
JavaTester.java:53: error: illegal start of expression public class Name{ ^ JavaTester.java:58: error: expected console.printf("Gary can code in Java!"); ^ JavaTester.java:58: error: illegal start of type console.printf("Gary can code in Java!"); ^ 3 errors
Jeff Janes
8,033 PointsActually, after looking at this challenge, the answer is a lot more simple than you think. Can you try the code below? It seems you're missing the part with setting the String to appear within the line.
%s will be replaced with whatever String you call after the comma in the printf method.
String firstName = "Gary";
console.printf("%s can code in Java!", firstName);
ISAIAH S
1,409 PointsAs Jeff Janes has said, you don't need the class
or the Console console = System.Console();
part, since Craig has already done them.
brian colliflower
15,433 PointsI agree with Isaiah and Jeff you have a lot of extra code you do not need you are getting tripped up on the curly braces and the extra code the whole code to finish it should look like this String firstName = "Brian"; console.printf("%s can code in Java!", firstName);
Jeff Janes
8,033 PointsJeff Janes
8,033 PointsIt looks like you're ending your class (with the }s) before the Console line. See if the code below works...