logo CodeStepByStep logo

sqrt

Language/Type: Java loops

Write a method named sqrt that accepts an integer N as a parameter and returns the square root of N as an integer. The challenge here is that you must not use Math.sqrt or Math.pow or other library methods to calculate the square root; rather, you must compute it yourself. You should return the square root as a truncated integer; for example, the square root of 7 is approximately 2.65, but your method should return 2. You may assume that the value of N passed is a positive integer.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.