Question: programming language is JAVA: Write a recursive method static int intSquareRoot(int n) {} // return the biggest number whose square is = 0. Use recursion.

programming language is JAVA:

Write a recursive method

static int intSquareRoot(int n) {} // return the biggest number whose square is <= n. Assume n >= 0.

Use recursion. No loops allowed. You will need to recurse on n/4 rather than n-1. That's because the method is called with some big values . If you recurse on n-1 those values will generate a StackOverflowError.

Of course Math.sqrt() or other Math class methods are not to be used in your implementation. You're just coding this using recursion and elementary operations .

Implementation Hint: intSquareRoot(n) is close to intSquareRoot(n/4) * 2. (Either equal to it or one more than it. You can tell which one, by squaring something.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!