i was wondering how many times the breakpoint is hit.
The question asks: for each of the first 4 hits, write down the values of currentMin, current Max and mid that can be seen in the debugger.
the values i have are: n=40, currentMin=0, currentMax=40 and mid=20.
is this four hits? or would i need to go round the cycle four times using the above values?
public class Breakpoint {
public int breakp() {
int n = 40;
int currentMin = 0;
int currentMax = n;
while (currentMin < currentMax) {
int mid = (currentMin + currentMax) / 2;
if (mid * mid + mid + 1 <= n)//breakpoint is on this line {
currentMin = mid;
} else {
currentMax = mid;
}
}
return currentMin;
}
public static void main(String[] args) {
Breakpoint b = new Breakpoint();
int a = b.breakp();
System.out.println(a);
}
}
If the breakpoint is post this line:
After 4 iteration the values should read..