Java examples for Language Basics:Operator
Newton's approximation algorithm
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); } }