下面贴上代码
package com.bird.software;
/**
*
* @author Bird
*
*/
public class Test5 {
public static void main(String[] args){
double x = 1;
double y = 1;
int a = 1;
int b = 3;
while(y > 1e-15){
y = y * ((double)a/b);
x += y;
a++;
b += 2;
}
System.out.println(x * 2);
}
}
运行结果为
3.141592653589791