本帖最后由 王渠 于 2012-6-4 15:47 编辑
- public class Exercise5_14 {
- public static void main(String[] args){
- System.out.println("i\tm(i)");
- for(int i =10;i<=100;i+=10)
- System.out.println(i+"\t"+sum(i));
- }
- public static double sum(int n){
- double sum = 0;
- int temp = 1;
- while(temp!=n){
- sum += 1/(2*temp-1.0)-1/(2*temp+1.0);
- temp++;
- }
- return 4 * sum;
- }
- }
复制代码 π = 4*(1-1/3+1/5-1/7+...+1/(2i-1)-1/(2i+1) |
|