1.7(求π的近似值)可以使用以下公式计算π:
编写程序,显示 和 的结果。在程序中用1.0代替1。
1.7 (Approximate π) can be computed using the following formula:
Write a program that displays the result of and .
use 1.0 instead of 1 in your program.
下面是参考答案代码:
public class CalculateTheApproximateNumberOfPIQuestion7 {
public static void main(String[] args) {
System.out.println("The Approximate Number Of PI : "
+ 4 * (1.0 - 1.0 / 3 + 1.0 / 5 - 1.0 / 7
+ 1.0 / 9 - 1.0 / 11));
System.out.println("The Approximate Number Of PI : "
+ 4 * (1.0 - 1.0 / 3 + 1.0 / 5 - 1.0 / 7
+ 1.0 / 9 - 1.0 / 11 + 1.0 / 13));
}
}
运行效果:
注:编程程序要养成良好习惯
如:1.文件名要用英文,具体一点
2.注释要英文
3.变量命名要具体,不要抽象(如:a,b,c等等),形式要驼峰化
4.整体书写风格要统一(不要这里是驼峰,那里是下划线,这里的逻辑段落空三行,那里相同的逻辑段落空5行等等)