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 trialSha Sud
4,175 Pointscode not running?
initialisation error
String response;
{
do
{
console.readLine("Do you understand do while loops?");
}while(response.equalsIgnoreCase("No"));
}
1 Answer
srikarvedantam
8,369 PointsThe code you posted has issues as below:
- The first pair of curly braces are redundant.
- After reading the user input, it is not being assigned to "response" String.
Here is a solution:
String response;
do {
response = console.readLine("Do you understand do while loops?");
} while (response.equals("No"));
console.printf("Because you said %s, you passed the test!", response);
Deividas Strioga
12,851 PointsDeividas Strioga
12,851 PointsHey Sha Sud, next time please give more info, like which step of the task you are on. You get initialization error because you declare String response, but you do not initialize it - do not give it a meaning. In a while statement you are checking if your String response is equal to "no", but you never gave it a meaning. You should put an answer from readLine to the String response. Tell me how it goes.