What output does the following program produce? Try running it with a couple of different values for n. Can you guess what this computes?
public class Exercisel2 {
private static int search(int a, int b, int n) {
int returnValue;
int mid = (a + b)/2;
System.out.printf(“Enter: a = %2d, b = %2d, mid = %2d\n”, a, b, mid);
if ((mid * mid ⇐ n) and (n<(mid+1) * (mid+1))) {
returnValue = mid;
}
else if (mid * mid > n) {
returnValue = search(a, mid-1, n);
}
else {
returnValue = search(mid+l, b, n);
} // end if
System.out.printf(“Leave: a = %2d, b = %2d, mid = %2d\n”, a, b, mid);
return returnValue;
} // end search
public static void main(String[] args) {
int n = 64;
System.out.printf(“For n = %2d, the result is %d\n”, n, search(1, n, n));
} // end main
} //end Exercise
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.