Calculate the square root of a number.
Anonymous
public double squareRoot(double x) { double epsilon = 0.000001; double base = 0; double increment = 1; while (increment > epsilon) { double diff = base*base - x; if (diff 0) { base -= increment; increment /= 10; } else { break; } } return base; }
Check out your Company Bowl for anonymous work chats.