Write a Java program to calculate the triangular function as follows:
Cos(x)=1 - x
2 /2!+ x
4/4!- x
6/ 6!...

要往前兩階
就乘以你要往前的那兩階的數字就好了
也就是下個數字和下下個數字....
何苦想要把奇數階層消去勒
我是笨蛋...
-------
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
double a=1,b=1,n,s=1,c = 0;
double active = 1; // 分子
double denominator = 1; // 分母
double multiple = 2 ;
System.out.println( "請輸入x" );
double x = keyboard.nextInt();
System.out.println( "請給予精確度n;n>0" );
n = keyboard.nextInt();
double result = 1.0;
for(int i = 1 ; i < n + 1 ; i ++ ){
active = active * x * x;
System.out.println( "x^: "+active );
denominator = -1*denominator * multiple * ( multiple-1 ); // 分母
System.out.println( "n^: "+denominator );
result += active / denominator;
multiple = multiple + 2;
}
System.out.println( "cos("+x+")="+ result );
// TODO code application logic here
}
}