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

Java Java Basics Perfecting the Prototype Looping until the value passes

Not sure how to do this exercise.

How do I continually prompt the user in a do while loop, and the loop should continue running as long as the response is No.

r h
r h
68,552 Points
import java.util.Scanner;
class Test{

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        boolean flag = true;
        while (flag) { 
            String response = input.next();
            if (response.toLowerCase().equals("yes")) { 
                flag = false;
            }
            // Rest of Loop Goes Here
        }
    }
}

could also do "while (response.equals("no"))"

1 Answer

Thanks Ryan. I already finished the exercise just a minute ago though I used this: <code> String response; boolean wrongAnswer; do { response = console.readLine("Do you understand do while loops?"); wrongAnswer = (response.equals("No")); if (wrongAnswer) { console.printf("Incorrect reply"); } } while(wrongAnswer); </code>