Answered step by step
Verified Expert Solution
Link Copied!

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

  1. 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:

  1. What output does the program produce when x = 64?

  1. Run the program and remove the error. Describe the steps that you took to find the error.

  1. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions