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 trialJennifer Gwaltney
119 PointsWhat am I doing wrong here?
I can't figure out what's wrong with my code.
// I have imported java.io.Console for you. It is a variable called console.
String firstName = "Jennifer";
console.readLine(firstName);
String lastName = "May";
console.readLine(lastName);
console.printf("First name: %s\n", firstName);
1 Answer
Yanuar Prakoso
15,196 PointsHi Jennifer After I look into the challenge I think you make a mistake on declaring the variable. It should be receiving the value from the user input using console.readLine() method. You are not supposed to give value to the firstName and lastName variable inside the code. Here is how I code it up until the same stage as you are:
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("please enter your first name: ");
String lastName = console.readLine("please enter your last name: ");
console.printf("First name: %s%n", firstName);
or if you still insist on using your style of coding it should be written as:
// I have imported java.io.Console for you. It is a variable called console.
String firstName;
firstName = console.readLine("please enter your first name: ");
String lastName;
lastName = console.readLine("please enter your last name: ");
console.printf("First name: %s\n", firstName);
please note that readLine method will receive input from the user and it will prompt anything written inside the bracket and double quotes (" .....").
I hope this will help you. And I think you will be able to answer the next part of the challenge by yourself after you fix the mistakes.