Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The following code is supposed to compute the floor of the square root of the input value x . (The floor of a number n
- The following code is supposed to compute the floor of the square root of the input value x. (The floor of a number n is the largest integer less then or equal to n.)
public static void main(String args[]) { int x; // input value Scanner input = new Scanner(System.in); // read input x = input.nextInt(); FloorOfX obj = new FloorOfX(); int result = obj.computeIt(x); System.out.println("The floor of the square root of " + x + " is " + result); input.close(); }
int computeIt(int x) { int result = 0; // will equal floor of sqrt(x) int temp1 = 1; int temp2 = 1; // compute floor while (temp1 < x) { ++result; temp2 += 2; temp1 += temp2; } // end while return result; }
This program contains an error:
- What output does the program produce when x = 64?
- Run the program and remove the error. Describe the steps that you took to find the error.
- How can you make the program more user friendly and fail-safe?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started