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
中使用1
代替3 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
答案 0 :(得分: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)));
答案 1 :(得分:0)
在两个近似值中你都省略了+(1.0 / 9.0)