/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author LH
 */
public class Sin
{

    public static void main(String[] args) throws Exception
    {
        InteractiveIO.write(sin(Math.PI / 2) + "");
    }

    public static double sin(double x) throws Exception
    {
        int k = 0, n = 1000;
        double maxError = 1e-10, sum = 0.0, xk = x;
        while (Math.abs(xk) >= maxError && k <= n)
        {
            sum += xk;
            InteractiveIO.write("k: " + k + " xk: " + xk + " sum: " + sum);
            k++;
            xk = -xk * x * x / (2 * k) / (2 * k + 1);
        }
        return sum + xk;

    }
}
