title: Binary Search to Compute Square root (Java)
body: <p>I need help writing a program that uses binary search to recursively compute a square root (rounded down to the nearest integer) of an input non-negative integer.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Sqrt {
  
    public static void main(String[] args) {
  
      Scanner console = new Scanner(System.in);
  
      System.out.print("Enter A Valid Integer: ");
  
      int value = console.nextInt();
  
      calculateSquareRoot(value);
  
    }
  
      public static int calculateSquareRoot(int value) {
        while (value &gt; 0) {
        double sqrt = (int) Math.sqrt(value);
        System.out.println(sqrt);
      }
      return -1;
      }
  }
  </code></pre>
  
  <p>The fact that it has to use binary search to compute the square root is the part that is confusing me. If anyone has any suggestions on how to do this, it would be greatly appreciated. Thank you</p>