Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

If you look at problem1(), there is an infinite loop. If you put a breakpoint on

ID: 3905020 • Letter: I

Question

If you look at problem1(), there is an infinite loop. If you put a breakpoint on line 15, you will see it doesn't stop.

What could you do to make the loop eventually stop?

boolean stop = false;
int count = 100;
String choice = "";
  
//Do NOT delete any code from the following method. Only add/change.
public void problem1()
{
while(!stop)
{
while(count > 0)
{
System.out.println("Count is: " + count);

}
do
{
System.out.println("Count is " + count);

}
while(count < 50);
stop = true;
  
}
}

Explanation / Answer

boolean stop = false; int count = 100; String choice = ""; //Do NOT delete any code from the following method. Only add/change. public void problem1() { while(!stop) { while(count > 0) { System.out.println("Count is: " + count); count--; } do { System.out.println("Count is " + count); count++; } while(count < 50); stop = true; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote