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

how do i complete this do while loop question?

String response; boolean no; do { response = console.readLine("Do you understand do while? "); no = (response.equalsIgnoreCase("No")); if (no) { console.printf("Because you said <response>, you passed the test! \n\n"); } }while (no);

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.\
String  response;
boolean no;
do {
  response = console.readLine("Do you understand do while? ");
  no = (response.equalsIgnoreCase("No"));
  if (no) {
  console.printf("Because you said <response>, you passed the test! \n\n");
  }
}while (no);

1 Answer

Chase Marchione
Chase Marchione
155,055 Points

Hi Kofi Jr.,

1) \n is used to add a new line to a string, which we won't need in this case.

2) What the objective actually wants us to do is include the user's response (which we store in the response variable) in our print out to the screen. To do that, we'll use a placeholder called a string formatter, which we use by typing %s at the place in the string in which we want our variable's contents to be displayed. So that the Java compiler knows which variable we're talking about, we'll add a comma after the string and type the name of the variable we want to use. This way, the compiler knows what string variable to replace %s with.

In short, you'll want to change this line:

console.printf("Because you said <response>, you passed the test! \n\n");

to

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

Hope this helps!