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 trialFrank Beaver
836 PointsJava Basics; Do While Loops; console.printf(3/3 "<response>");
I no longer understand what is being asked of me in this Bummer response. I have made many different versions of this code, many times including this one with no compiler errors but still get a try again prompt. This task has turned me into The Crypt Keeper; HELP!
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean respponse;
do {
response= console.readLine("Do you understand do while loops?");
response.equals("No");
console.printf("Bummer");
respponse= (response.equals("<response>")) ||
(response.equals("<>"));
if (response.equals(respponse)) {
console.printf("Because you said <response>, you passed the test!");
System.exit(0);}
}while(response.equals("No"));
console.printf("Because you said <response>, you passed the test!");
2 Answers
joelearner
54,915 PointsHi Frank,
You have almost the complete answer contained within your code already. There are more variables than what you really need at this point. Here is what you should keep (with *** to point it out):
// I have initialized a java.io.Console for you. It is in a variable named console.
***String response;***
boolean respponse;
***do {
response= console.readLine("Do you understand do while loops?");***
response.equals("No");
console.printf("Bummer");
respponse= (response.equals("<response>")) ||
(response.equals("<>"));
if (response.equals(respponse)) {
console.printf("Because you said <response>, you passed the test!");
System.exit(0);}
***}while(response.equals("No"));
console.printf("Because you said <response>, you passed the test!");***
Then you are down to the following code:
String response;
do {
response = console.readLine("Do you understand while loops?");
} while(response.equals("No"));
console.printf("Because you said <response>, you passed the test!");;
Now, you only need to make a change to the printf statement. Since printf involves string conversion, I would suggest replacing <response> with %s and specifying that the response variable requires a conversion. Something like this:
console.printf("Because you said %s, you passed the test!", response);
So your finished code should look something like this:
String response;
do {
response = console.readLine("Do you understand while loops?");
} while(response.equals("No"));
console.printf("Because you said %s, you passed the test!", response);
Cheers!
Matt Taylor
2,406 PointsYes, finally. I can go to sleep now! Thanks a lot Joelearner.
Frank Beaver
836 PointsFrank Beaver
836 PointsI'm finally out of that Crypt, thank you joelearner!!!