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

In the last challenge of Java Basics Last Step

Ok I am still stuck in the loop. I have printed and used the the right coding and the program is still asking if I used console.printf Why?!

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
 String response = console.readLine("Do you understand do while loops?  ");

do {
  response = console.readLine("Enter no:  ");
}while ( response.equals( "No"));

console.printf("Because you said Do you understand do while loops?  No , you passed the test!   ");

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Sara;

A couple of things come to mind based on your code.

  1. You have explicitly declared what response is outside of the do... while loop and then redefined it inside the loop. Try just defining response as a String without assigning it a value outside the loop and then gathering the appropriate response inside the loop.
  2. In your console.printf statement, I don't see you using the string formatter and providing the response the user inputted in your outputted statement.

Without explicitly giving away the answer, I think the challenge is looking for something similar to:

// I have initialized a java.io.Console for you. It is in a variable named console.

String userName;

do {
userInput = console.readLine("Greetings, what is your name?");
} while (userInput.equals("Ken"));

console.printf ("Because you are named %s, you passed the test!", userInput);

If you try that code above, I would never be able to get out of the loop, right?

Post back if you are still stuck.

Happy coding,

Ken