English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類
0

用Method寫下面的:

m ( i )=4(1-1/3+1/5-1/7+1/9-1/11+1/13-..............-1/2i-1+1/2i+1)

謝謝

2007-12-09 15:07:29 · 1 個解答 · 發問者 花兒 1 in 電腦與網際網路 程式設計

1 個解答

//Power by Eclipse
//Download Site: http://www.eclipse.org/
import java.io.*;
import java.util.*;
public class TEST
//檔名:TEST.java
{
public static void main(String[] args)
{
PrintStream o=new PrintStream(System.out);
Scanner in=new Scanner(System.in);
o.printf("Java Math.PI= %.16f\n",Math.PI);
o.printf("Input i: ");
o.printf("My PI= %.16f\n",pi((int)in.nextDouble()));
}
public static double pi(int x)
{
double m=0;
for(int i=0;i {
m+=Math.pow(-1,i)/(2*i+1);
}
return 4*m;
}
}

2007-12-09 15:38:06 · answer #1 · answered by Big_John-tw 7 · 0 0

fedest.com, questions and answers