The following code is supposed to compute the floor of the square root of its input value x. (The floor of a number n is the largest integer less dian or equal to n.)
// Computes and writes floor(sqrt(x)) for
// an input value x >= 0.
public static void main(String args[]) {
int x; // input value
Scanner input = new Scanner(System.in);
// initialize
int result = 0; // will equal floor of sqrt(x)
int tempi = 1;
int temp2 = 1;
// read input
x = input.nextlnt();
// compute floor
while (temp1
++result;
temp2 += 2;
temp1 += temp2;
} // end while
System.out.println(“The floor of the square root of ”+ x + “ is ” + result);
} // end main
This program contains an error.
a. What output does the program produce when x = 64?
b. Run the program and remove the error. Describe the steps that you took to find the error.
c. How can you make the program more user friendly and fail-safe?
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.