find square root

public class Solution {
    public static void main(String[] args) {
        Scanner ip = new Scanner(System.in);
        System.out.print("Enter a number: ");
        double n = ip.nextDouble();
        System.out.println(sqrt(n));
        ip.close();
    }

    public static double sqrt(double number) {
        double t;

        double squareRoot = number / 2;

        do {
            t = squareRoot;
            squareRoot = (t + (number / t)) / 2;
        } while ((t - squareRoot) != 0);

        return squareRoot;
    }
}
原文地址:https://www.cnblogs.com/sea-stream/p/12013100.html