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.

Java

rojy mathew
rojy mathew
145 Points

code challenge:define a string variable

Hi,

I couldnt find the syntax error. below is my code

public class Rojy { public static void main(String[] args) { Console console = System.console(); String firstname = "rojy"; console.printf("hi everyone im %s\n",firstname);

}

}

error recieved

JavaTester.java:73: error: illegal start of expression public class Rojy { ^ 1 error

2 Answers

Rojy, you didn't give a link to the challenge, so I can't see it there. When I put it in my IDE it compiles fine. So there are no syntax errors. It may be that you didn't do exactly what the challenge asked you to do. Challenges can be quick picky!!

If you include a link that would be a big help.

Rojy, you were doing much more than what the challenge asked for. You don't need a class, or to recreate the Console object. This will do fine:

String firstName = "Rojy";
console.printf("%s can code in Java!", firstName);