1 public class Outcome{ 2 public static void main(String[] args){ 3 double x, y; 4 x=4*(1.0-1.0/3+1.0/5-1.0/7+1.0/9-1.0/11); 5 y=4*(1.0-1.0/3+1.0/5-1.0/7+1.0/9-1.0/11+1.0/13); 6 System.out.println(x); 7 System.out.println(y); 8 } 9 }
本文介绍了一个使用Java编写的简单程序,该程序通过级数求和的方法来近似计算π的值。程序中定义了两个变量x和y,分别计算了包含6项和7项的级数,展示了如何在Java中进行浮点数运算并输出结果。
1 public class Outcome{ 2 public static void main(String[] args){ 3 double x, y; 4 x=4*(1.0-1.0/3+1.0/5-1.0/7+1.0/9-1.0/11); 5 y=4*(1.0-1.0/3+1.0/5-1.0/7+1.0/9-1.0/11+1.0/13); 6 System.out.println(x); 7 System.out.println(y); 8 } 9 }
转载于:https://www.cnblogs.com/cherrydream/p/9799214.html

被折叠的 条评论
为什么被折叠?
