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 trial
Leon Kenedy
Courses Plus Student 9,149 PointsCan you help me with part two with Java?
I really need help to this code challengehttp://teamtreehouse.com/library/java-basics/perfecting-the-prototype/looping-until-the-value-passes. Please help me with this.
Leon Kenedy
Courses Plus Student 9,149 PointsString who;
do{
//Here is the prompting code
console.printf("Knock Knock.\n");
who = console.readLine("Who's there? ");
console.printf("%s who?\n", who);
} while(who.equalsIgnoreCase("banana"));
1 Answer
Ken Alger
Treehouse TeacherLeon;
Let's sort this out.
Here is what this task is asking:
Print out the punchline, after the while loop completes, using the who variable.
The prompting code is accepting user input and for the sake of argument let's assume that it only accepts two words (strings) as input, Orange or Banana.
If you look at the comments, as long as we keep putting in Banana, it outputs Banana who. Hopefully that makes sense and you are good with that thus far.
So Task 2 want's us to produce the punchline:
Orange you glad I didn't say Banana again?
using the who variable, which you should be comfortable doing at this point in the Java Basics course.
Our output code, therefore, needs to look like:
console.printf("%s you glad you didn't say Banana again?", who);
Now where does that line of code go? Well, the task instructions tell us that it needs to be after the while loop completes, which makes sense since if who = "Orange" we no longer need to be inside the do... while loop.
Hopefully that points you in the correct direction.
Ken
Leon Kenedy
Courses Plus Student 9,149 PointsThanks, I was trying to do something else earlier, so thank you so much man.
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherLeon;
Can you show me the code you have tried?
Ken