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 trialANURAG SINGH
Courses Plus Student 349 Pointserror
getting following error " Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:3210) at java.util.Arrays.copyOf(Arrays.java:3181) at java.util.ArrayList.grow(ArrayList.java:261) at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:235) at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:227) at java.util.ArrayList.add(ArrayList.java:458) at JavaTester$MockConsole.printf(JavaTester.java:41) at JavaTester.run(JavaTester.java:123) at JavaTester.main(JavaTester.java:90) " I feel the code is going in infinite loop
// 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?" );
Boolean result;
do {
result = response.equals("No");
console.printf("try Again" );
}
while (result);
1 Answer
Kourosh Raeen
23,733 PointsThe value of result is never changing. You also need to keep asking the user until the response is something other than "No". Try this:
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do {
response = console.readLine("Do you understand do while loops?" );
} while(response == "No");