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

Geovani Estacio
PLUS
Geovani Estacio
Courses Plus Student 1,875 Points

Please help, how do I implement this?

Finally, using console.printf print out a formatted string that says "Because you said <response>, you passed the test!"

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do{
  response = console.readLine("Do you understand do while loops?");
}
while(response.equals("No"));{
 console.printf("Because you said NO, you passed the test");}

3 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

when it tells you to print ...<response>.... it's not saying to literally type in a response like you have typed NO, it's asking you to use string interpolation to insert the value held by the response variable. that's the only change you need to make to pass.

It wants you to printf a formatted string, passing in the response to a placeholder. If you check this page, you can get a better idea of what you should do :)

Also, the unnecessary braces {} around your printf() need to be removed

maxmaltsev
maxmaltsev
3,419 Points

Mike did a great job guiding you through, and I am going to "chew" it for you. Printf stands for formatted - it allows you to do not use inconvenient string concatenation by using %s for strings and %d for numbers operators. More details here.

console.printf("Because you said %s, you passed the test!", response);

This is much more convenient rather than using string concatenation:

System.out.println("Because you said " + response + ", you passed the test!");

Your actual code:

// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
  do {
    response = console.readLine("Do you understand do while loops?");
  } while (response.equals("No"));
console.printf("Because you said %s, you passed the test!", response);