public class Main {
	private static final double TOLERANCE = 1e-10;
	public int mySqrt(int x) {
	    if (x < 2)
	        return x;
	    double lowerBound = 0.0, upperBound = x, midPoint = 0.0;
	    while (upperBound - lowerBound >= TOLERANCE) {
	        midPoint = lowerBound + (upperBound - lowerBound) / 2;
	        double square = Math.pow(midPoint, 2);
	        if (Double.compare(square, x) < 0)
	            lowerBound = midPoint;
	        else if (Double.compare(square, x) > 0)
	            upperBound = midPoint;
	        else
	            return (int) midPoint;
	    }
	    return (int) midPoint;
	}
	public static void main(final String[] args){
		final Main main = new Main();
		final int[] tests = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 24, 25, 26};
		for(final int test: tests){
			System.out.format("Floor sqrt(%d) = %d%n", test, main.mySqrt(test));
		}
	}
}