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 trialmike LaBianca
Courses Plus Student 2,456 PointsI now I am close, just need some help
not sure where to go from here
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do {
response = console.printf("Do you understand do while loops?");
} while (response == "No");
response = console.printf("Because you said resonse, you passed the test!");
2 Answers
Christopher Augg
21,223 PointsMike,
Way to go! Just a few hints to get you on track:
String response;
do {
response = console.printf("Do you understand do while loops?"); //readLine(" ... ")?
} while (response == "No"); //using == test if the String objects are equal and not the Strings. Use .equals()
//Don't assign this to response. You just need to print out the message.
//Remember the format : console.printf("something something blah %s", variable);
response = console.printf("Because you said resonse, you passed the test!");
Hope this helps.
Regards,
Chris
Grigorij Schleifer
10,365 PointsHere you dont need to create a new object of the Console class because the console object is already defined for you and you can use console.readLine() to store an Input in a String. You dont need to create console
Console console = System.console();
instead you use this
String inputFromUser = console.readLine("Do you understabnd the do/while Loop? ");
If you want a do/while-loop that is asking the user, whether he understands ít. You can do it this way
do{
String inputFromUser = console.readLine("Do you understabnd the do/while Loop? ");
// the users input is stored in the inputFromUser variable
// when the user types "no" the loop repeats, when "yes" the loop is over
//The user can input No (uppercased) and the loop is also over
}while(inputFromUser .equalsIgnoreCase("no"));
I hope it helps a little