Problem

The following code is supposed to compute the floor of the square root of its input value...

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?

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 2
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT