如何求圆周率(pai)的,前100位? 谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一、基础公式: ⑴ π=180°sinθ∕θ 、 ⑶ π=180°tgθ∕θ 、 (θ→0°.θ>0°) 二、 派生公式: ⑸ π=(n/2)*sin(360°∕n) 、 ⑺ π=(n/2)*tg(360°∕n) 、 (n→∞, n≥5) 派生公式: ⑼ π=nsin(180°∕n) 、 ⑾ π=ntg(180°∕n) 、 (n→∞,n≥3) 三、专业公式: ①π= 2^n√(2-√(2+…√2)…) ②π=3×2^n√(2-√(2+…√3)…) ③π=2×2^n√(2-√(2+…√2)…)/√(2+√(2+…√2)…) ④π=6×2^n√(2-√(2+…√3)…)/√(2+√(2+…√3)…) (n→∞,根式中有n个2) 如果你真的想要那样的精度,请执行下面的程序,再等上几个小时 import java.math.*; public class ForPI { //PI=4*(1-1/3+1/5-1/7...) public static String forPI(int a){ BigDecimal result,index,temp,flag,b,c; b=new BigDecimal(1,new MathContext(a,RoundingMode.HALF_UP));//分子 c=new BigDecimal(2);//增量 result=new BigDecimal(0,new MathContext(a,RoundingMode.HALF_UP)); index=new BigDecimal(1);//分母 temp=new BigDecimal(1,new MathContext(a,RoundingMode.HALF_UP)); flag=new BigDecimal(0.1); flag=flag.pow(a);//精度 while(temp.abs().compareTo(flag)==1){ temp=b.divide(index); result.add(temp); index.add(c); index=index.negate(); } result=result.multiply(new BigDecimal(4)); return result.toPlainString(); } public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(forPI(100)); } } 楼上疯了...要几个小时...你下个superΠ,测试cpu运算能力的软件...算104万位的,才用25秒.. 100位而已,我背都背出来了。还可以google it。 System.out.println("Pi=3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209 74944 5923078164 06286 20899 86280 34825 34211 70679 "); 求高手————给我这个初学者解答(代码都通过了,不知怎么添加照片) 突然有一点迷惑,关于私有变量 我用post模拟登陆,成功后,有个post提交的参数,调用的sendPost方法跟模拟登陆的一样,为什么无法成功? XStream读取不到对象的属性 java中IO流将字节码转换成图片的问题? jdk 7.0有什么更新 高首赐教 關於參數“String ...str”的問題 我的程序打了包(jar),就找不到加载的其它jar了,奇怪,为什么会这样??? 求教:关于JAVA程序中汉字转换的问题 求java程序写圆周率的算法 屏蔽超链接<a>状态栏显示地址的问题,怎么弄啊!
⑶ π=180°tgθ∕θ 、
(θ→0°.θ>0°)
二、
派生公式:
⑸ π=(n/2)*sin(360°∕n) 、
⑺ π=(n/2)*tg(360°∕n) 、
(n→∞, n≥5) 派生公式:
⑼ π=nsin(180°∕n) 、
⑾ π=ntg(180°∕n) 、
(n→∞,n≥3) 三、专业公式: ①π= 2^n√(2-√(2+…√2)…)
②π=3×2^n√(2-√(2+…√3)…)
③π=2×2^n√(2-√(2+…√2)…)/√(2+√(2+…√2)…)
④π=6×2^n√(2-√(2+…√3)…)/√(2+√(2+…√3)…)
(n→∞,根式中有n个2)
import java.math.*;
public class ForPI { //PI=4*(1-1/3+1/5-1/7...)
public static String forPI(int a){ BigDecimal result,index,temp,flag,b,c;
b=new BigDecimal(1,new MathContext(a,RoundingMode.HALF_UP));//分子
c=new BigDecimal(2);//增量
result=new BigDecimal(0,new MathContext(a,RoundingMode.HALF_UP));
index=new BigDecimal(1);//分母
temp=new BigDecimal(1,new MathContext(a,RoundingMode.HALF_UP));
flag=new BigDecimal(0.1);
flag=flag.pow(a);//精度
while(temp.abs().compareTo(flag)==1){
temp=b.divide(index);
result.add(temp);
index.add(c);
index=index.negate();
}
result=result.multiply(new BigDecimal(4));
return result.toPlainString(); }
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(forPI(100)); } }
50288 41971 69399 37510 58209 74944 5923078164 06286 20899 86280 34825 34211 70679
");