title: Java Newton Iteration
body: <p>I'm trying to make a square root calculator with my own function which is sqrt and borrowing a already made one to test accuracy. The issue is every time I output my guess to the screen after putting it into the function the numbers just return as the same number inputted but it has a .0 on it. An example is, when I put in the number 2 I get back 2.0 which is wrong. Please help :)</p>
  
  <pre><code>   import java.io.IOException;
  import java.util.Scanner;
  
  public class test {
  /**
   * Main method.
   *
   * @param args
   *            the command line arguments
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {
      Scanner data = new Scanner(System.in);
  
      double root;
      /*
       * Put your main program code here; it may call myMethod as shown
       */
      System.out.println("Please enter a root to be calculated:");
      root = data.nextDouble();
      double actual = root;
      sqrt(root);
      sqrt_(actual);
      System.out.println(root);
      System.out.println(actual);
      /*
       * Close input and output streams
       */
  
  }
  
  /**
   * Computes estimate of square root of x to within relative error 0.01%.
   *
   * @param x
   *            positive number to compute square root of
   * @return estimate of square root
   */
  private static double sqrt(double x) {
  
      double epilson = 0.0001;
      double approx = 1;
      int count = 0;
      while ((Math.abs(approx - (x / approx)) &gt; (0.0001 * approx))
              &amp;&amp; (count &lt; 100)) {
          approx = 0.5 * (approx + (x / approx));
          count++;
      }
      return approx;
  
  }
  
  public static double sqrt_(double c) {
      if (c &lt; 0) {
          return Double.NaN;
      }
      double EPS = 1E-15;
      double t = c;
      while (Math.abs(t - c / t) &gt; EPS * t) {
          t = (c / t + t) / 2.0;
      }
      return t;
  }
  }
  </code></pre>