Last active
October 16, 2015 15:49
-
-
Save a0x/ac548f8f72bc5f6ca2dd to your computer and use it in GitHub Desktop.
Revisions
-
a0x renamed this gist
Oct 16, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
a0x revised this gist
Oct 16, 2015 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ public class TestPI{ public static void main(String[] args){ // args[0] 是运行时输入的参数,也可以预先在程序中设定好数值。 @@ -15,5 +14,4 @@ public class TestPI{ } System.out.println(result); } } -
a0x revised this gist
Oct 16, 2015 . 1 changed file with 18 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,19 @@ ```java public class TestPI{ public static void main(String[] args){ // args[0] 是运行时输入的参数,也可以预先在程序中设定好数值。 int time = new Integer(args[0]).intValue(); double result = 0; for(int i = 1; i <= time; i++){ double value = 4.0 / (2.0 * i - 1.0); if (i % 2 == 1) { result += value; } else { result -= value; } } System.out.println(result); } } ``` -
a0x created this gist
Oct 16, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ public class TestPI{ public static void main(String[] args){ int time=new Integer(args[0]).intValue();//输入的项数; double result=0;//用来保存结果 for(int i=1;i<=time;i++){ double value=4.0/(2*i-1); if (i % 2 == 1) result+=value;//基数加偶数减 else result-=value; } System.out.println(result); } }