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