Discuss / Java / 计算PI

计算PI

Topic source

Angular2club

#1 Created at ... [Delete] [Delete and Lock User]

```java

public class Hello {

public static void main(String[] args) {

double PI = 0;

String currentOp = "-";

double result = 1;

for (long i = 3; i <= 1000000000; i += 2) {

if (currentOp.equals("-")) {

result -= 1.0 / i;

currentOp = "+";

} else {

result += 1.0 / i;

currentOp = "-";

}

}

PI = result * 4;

System.out.print("PI is:" + PI);

}

private int add(int x, int y) {

return x + y;

}

}

```

感觉有点蠢


  • 1

Reply