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 trialDaniel Avila
Courses Plus Student 1,474 PointsHow do I use console.printf to print out a formatted string that says "Because you said <response>, you passed the test
I'm stuck on the last task and I'm not sure why it is wrong.
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean loopResponse;
do {
response=console.readLine("Do you understand do while loops?");
loopResponse=(response.equalsIgnoreCase("No"));
if (loopResponse) {
console.printf("Because you said <response>, you passed the test!\n");
}
} while(loopResponse);
2 Answers
alex novickis
34,894 Pointsguessing if you are here you need the last bit
but console.printf(""Because you said " + response + ",you passed the test!");
is not making the tester happy
try instead using %s format string with response as parameter
Seth Kroger
56,414 Points2 things: First, because you are already looping until you get a correct answer, you should print it outside the loop. Second, you need to replace "<response>" with the value of response (printf() has a way to do just that).
Stacey Fenton
5,501 PointsStacey Fenton
5,501 PointsMy code works - hope it help you!
String response = console.readLine ("Do you understand do while loops?"); boolean repeatResponse;
while (repeatResponse); console.printf ("Good job!");