Newton's approximation algorithm - Java Language Basics

Java examples for Language Basics:Operator

Description

Newton's approximation algorithm

Demo Code

public class Main {
  public static void main(String arg[]) {
    double a = 2.0, x, xold;
    x = a;/*from ww  w.j a va2s. co m*/
    do {
      xold = x;
      // compute one iteration
      x = (xold + a / xold) / 2.0;
      System.out.println(x);
    } while (Math.abs(x - xold) > 1e-10);
  }
}

Result


Related Tutorials