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 trialNancy Melucci
Courses Plus Student 36,143 PointsHard to read this version of Java, can't pass challenge
I really love this and all Treehouse tutorials. But I am used to starting my programs with public static void main(String[] args) { and not used to the console.printf version this tutorial is using (System.out.println.();). It's harder for me to read the code and I can't use my IDE (NetBeans) to test before doing the challenges. Anyway...why can't I make my challenge answer pass....I've compared this with various online Java sources for the do/while structure.
String who;
do {
console.printf("Knock Knock.\n");
String who = console.readLine("Who's there? ");
console.printf("%s who?\n", who);
} while(who.equalsIgnoreCase("banana"));
}
2 Answers
Ryan Duchene
Courses Plus Student 46,022 PointsYou have an extra closing curly brace after the while
conditional that you don't need. Also, when you modify the who
variable inside of the do-while
loop, you don't need to place its type before its name, as you've already defined that variable. :)
String who;
do {
console.printf("Knock Knock.\n");
// Person B asks and Person A's response is stored in the String who:
who = console.readLine("Who's there? ");
// Person B responds:
console.printf("%s who?\n", who);
} while (who.equalsIgnoreCase("banana"));
Nancy Melucci
Courses Plus Student 36,143 PointsThanks....every version I've seen has a closing brace....but, I removed those two things and it worked great.
Ryan Duchene
Courses Plus Student 46,022 PointsIt does have a closing brace, but that brace comes after the do block:
do {
console.printf("Knock Knock.\n");
// Person B asks and Person A's response is stored in the String who:
who = console.readLine("Who's there? ");
// Person B responds:
console.printf("%s who?\n", who);
} // <-- there's the brace
Anyways, glad I could help! Happy coding! :)