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 trialM Costa
1,621 PointsString print call is failing
Trying to pass in <response> at the end of the loop, but it's printing '<response>' literally, rather than the users response.
I posted something similar a couple of days ago and managed to solve this, but I'm coming across this problem again, not sure if this an issue with scope.
// I have initialized a java.io.Console for you. It is in a variable named console.
boolean failTest;
String response;
do {
response = console.readLine("Do you understand do while loops? ");
failTest = (response.equalsIgnoreCase("No"));
if (failTest){
console.printf("Are you sure?, Try again. ");}
} while (failTest);
console.printf("Because you said <response>, you passed the test!");
1 Answer
Steven Parker
231,275 PointsVariable substitution isn't performed automatically when something is enclosed in angle brackets. But you can use a substitution token placed where you want the value shown, and supply the variable as an additional argument:
console.printf("Because you said %s, you passed the test!", response);
M Costa
1,621 PointsM Costa
1,621 PointsI've now figured this out using formatted stings, but I was under the impression you could pass console.printf("Because you said <response>) the same way, maybe not