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 trialJocelyn Gan
1,481 Pointsdefine a string variable
// I have setup a java.io.Console object for you named console
import java.io.Console; class FirstAttempt{ public static void main (String [] args){ Console console = System.console(); String firstName = "Jocelyn";
console.printf("My first name is %s\n",firstName);
} }
// I have setup a java.io.Console object for you named console
import java.io.Console;
class FirstAttempt{
public static void main (String [] args){
Console console = System.console();
String firstName = "Jocelyn";
console.printf("My first name is %s\n",firstName);
}
}
4 Answers
Jocelyn Gan
1,481 Pointsthx Adrian..actually the answer only:
String firstName = "Jocelyn";
console.printf("My first name is %s\n",firstName);
haha.. thx =]
adriantennison
3,090 PointsDeclare the class as public
Example:
public class FirstAttempt{ //your code here }
Craig Dennis
Treehouse TeacherYeah, you don't need the class wrapper yet. Nice job overachieving though ;)
We'll get to it. Sorry for the confusion. I'll add a clear error for that.
Jocelyn Gan
1,481 PointsTHX =]
adriantennison
3,090 PointsRemove import java.io.console; this would fix because its already been hard coded as said in the comment
Jocelyn Gan
1,481 PointsThx.. but public class Name{ public static void main (String [] args){ Console console = System.console(); String firstName = "Jocelyn";
console.printf("My first name is %s\n",firstName);
} }
still hav e error
Jocelyn Gan
1,481 PointsJavaTester.java:76: error: illegal start of expression public class Name{ ^ 1 error
Jocelyn Gan
1,481 PointsJocelyn Gan
1,481 Pointsoutput: JavaTester.java:74: error: illegal start of expression import java.io.Console; ^ JavaTester.java:74: error: not a statement import java.io.Console; ^ 2 errors