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

Cannot get answer to print

Can someone tell me why the "Because you answered 'Yes', you passed the test" will not print. Basically if the answer is not "No" I want this to be the response. Thanks! // I have initialized a java.io.Console for you. It is in a variable named console. String response; boolean answer; do { response = console.readLine("Do you understand while loops?"); answer = (response.equalsIgnoreCase("No")); if (answer) {console.printf("Do you understand while loops?"); } } while(answer); console.printf("Because you answered Yes, you passed the test")

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

1 Answer

Brendon Butler
Brendon Butler
4,254 Points

Looks like you need to format our output string in your last line. You're also missing a semi-colon at the end of that line (I assume this was just a copy/paste issue.

Like in the previous tutorials, you'll want to use %s to identify strings to be replaced by the printf formatter method. Here's an example:

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