-4

1.7 (Approximate p) p可以使用以下公式计算:

编写一个显示结果的程序4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11)

4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13)

在你的 程序中使用1.0而不是。13 5 7 9 11 13

我的代码:

/**
* This program will print two different results in
* trying to reach a approximation of pi.
*
* Author: X   Date: 11/11/2013
*/
public class one_seven
{
    public static void main(String[] args)
    {
        System.out.print("This will print 1st approximation: ");
        System.out.println(4*(1.0-(1.0/3)+(1.0/5)-(1.0/7)-(1.0/11)));
        System.out.print("This will print 2nd approximation: ");
        System.out.println(4*(1.0-(1.0/3)+(1.0/5)-(1.0/7)-(1.0/11)+(1.0/13)));
    }
}

我的代码输出是:

This will print 1st approximation: 2.531601731601732
This will print 2nd approximation: 2.83929403929404
4

2 回答 2

1

你错过了这个1.0/9词。

 System.out.print("This will print 1st approximation: ");
 System.out.println(4*(1.0-(1.0/3)+(1.0/5)-(1.0/7)+(1.0/9)-(1.0/11)));
 System.out.print("This will print 2nd approximation: ");
 System.out.println(4*(1.0-(1.0/3)+(1.0/5)-(1.0/7)+(1.0/9)-(1.0/11)+(1.0/13)));
于 2013-11-12T01:38:28.403 回答
0

在这两个近似值中,您都忽略了 + (1.0/9.0)

于 2013-11-12T01:40:18.003 回答