(近似求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)和4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13)的结果。在程序中用1.0代替1。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dome1_7;
/**
*
* @author Administrator
*/
public class Dome1_7 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
double Pi = 0.0;
Pi = 4 * (1.0 - 1.0/3 + 1.0/5 - 1.0/7 + 1.0/9 - 1.0/11);
System.out.println(Pi);
Pi = 4 * (1.0 - 1.0/3 + 1.0/5 - 1.0/7 + 1.0/9 - 1.0/11 + 1.0/13);
System.out.println(Pi);
}
}