本人初学java 请各位高手指点一下为什么这个输出圆周率的程序输出结果为0.0

来源:百度知道 编辑:UC知道 时间:2024/06/09 11:44:05
class arctg
{ double arctg (double n)
{ double x;
x=n-(Math.pow(n,3.0)/3.0)+(Math.pow(n,5.0)/5.0)-(Math.pow(n,7.0)/7.0)+(Math.pow(n,9.0)/9.0)-(Math.pow(n,11.0)/11.0)+(Math.pow(n,13.0)/13.0)-(Math.pow(n,15)/15);
return x;
}
}
public class yuanzhoulv {
public static void main(String args[])

{ double w;
arctg m=new arctg();
w=16*(m.arctg(1/5))-4*(m.arctg(1/239));
System.out.println(""+w);
}
}

class arctg
{ double arctg (double n)
{ double x;
x=n-(Math.pow(n,3.0)/3.0)+(Math.pow(n,5.0)/5.0)-(Math.pow(n,7.0)/7.0)+(Math.pow(n,9.0)/9.0)-(Math.pow(n,11.0)/11.0)+(Math.pow(n,13.0)/13.0)-(Math.pow(n,15)/15);
return x;
}
}
public class yuanzhoulv {
public static void main(String args[])

{ double w;
arctg m=new arctg();
w=16*(m.arctg(1/5))-4*(m.arctg(1/239));
System.out.println(""+w);
}
}????????

w=16*(m.arctg(1/5))-4*(m.arctg(1/239));

=>

w=16 * m.arctg(0) - 4 * m.arctg(0)

自己检查下,确保每个运算式都是在 double 状态下