Skip to content

Instantly share code, notes, and snippets.

@a0x
Last active October 16, 2015 15:49
Show Gist options
  • Save a0x/ac548f8f72bc5f6ca2dd to your computer and use it in GitHub Desktop.
Save a0x/ac548f8f72bc5f6ca2dd to your computer and use it in GitHub Desktop.

Revisions

  1. a0x renamed this gist Oct 16, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. a0x revised this gist Oct 16, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions Java - TestPi
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    ```java
    public class TestPI{
    public static void main(String[] args){
    // args[0] 是运行时输入的参数,也可以预先在程序中设定好数值。
    @@ -15,5 +14,4 @@ public class TestPI{
    }
    System.out.println(result);
    }
    }
    ```
    }
  3. a0x revised this gist Oct 16, 2015. 1 changed file with 18 additions and 11 deletions.
    29 changes: 18 additions & 11 deletions Java - TestPi
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,19 @@
    ```java
    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);
    }
    }
    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);
    }
    }
    ```
  4. a0x created this gist Oct 16, 2015.
    12 changes: 12 additions & 0 deletions Java - TestPi
    Original 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);
    }
    }