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 trialGregory Salinas
1,035 PointsWhat am I doing wrong?
What exactly am I doing wrong here?
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean answer;
do {
response = console.readLine("Do you understand do while loops?");
answer = (response.equalsIgnoreCase("No"));
if (answer) {
console.printf("Sorry mate. ");
} while (answer);
}
1 Answer
dmzstudio45
43,976 PointsYou're close. You just need to rearrange your code a little bit, and eliminate some of the code.
Task 1: Step 1: First, you declare your String variable.
Step 2: Prompt the user for a response to the question: "Do. you understand do while loops?", and save the response in the variable you declared in step 1.
Task 2: Create a "do while" loop to keep asking the user the same question as long as the answer is "no".
Here's an example:
String variable;
do { response = console.readLine("Question"); } while (response.equalsIgnoreCase("Answer"));
You don't need to Boolean variable, or the if statement. I hope that helps you.
Gregory Salinas
1,035 PointsThanks, man! got it finally after like two days of stalling.
Remi Tobias
19,358 PointsRemi Tobias
19,358 PointsI think your missing an instance of console
Console console = System.console();