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 trialThomas Branch
1,178 PointsJava quiz parser broken
I am doing the last quiz on the first section of the java track. There is no way to satisfy the quizzes third task. I can't see an error in this code.
String firstName = ""; String lastName = ""; console.readLine("first name", firstName); console.readLine("last name", lastName); console.printf('first name: %s', firstName);
However, the interpreter gives me a "bummer". I've played around with formatting between double quotes and single quotes, the ordering of the lines, etc. All with the same result.
// I have imported java.io.Console for you. It is a variable called console.
String firstName = "";
String lastName = "";
console.readLine("first name", firstName);
console.readLine("last name", lastName);
console.printf('first name: %s', firstName);
3 Answers
Craig Dennis
Treehouse TeacherHey Daniel,
In Java single quotes and double quotes make a difference.
console.printf('first name: %s', firstName);
Single quotes are used to represent a char
literal like this:
char letter = 'A';
String letters = "A";
They are different, we get into it in the next course, Java Objects. I should add a check assuming that error was a bit mind-blowing ;) Sorry for the frustration.
Mikkel Rasmussen
31,772 PointsIt shoud be
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("Enter your first name: ");
String lastName = console.readLine("Enter your last name: ");
console.printf("First name: %s", firstName);
console.printf("Last name: %s", lastName);
Thomas Branch
1,178 PointsHmmm, both should work. I passed tasks 1 & 2 with the readLines & string definitions as you see them.
Thanks for the fast response.