programmingex5 25 java

Solutions on MaxInterview for programmingex5 25 java by the best coders in the world

showing results for - "programmingex5 25 java"
Alessandra
23 Mar 2017
1public class ProgrammingEx5_25 {
2 public static void main(String[] args) {
3 
4  double pi = 0;
5 
6  for (int i = 1; i <= 100000; i++) {
7   pi += Math.pow(-1, i + 1) / (2 * i - 1);
8   if (i == 10000) {
9    System.out.println("Pi at i = 10000 is " + pi*4);
10   } else if (i == 20000) {
11    System.out.println("Pi at i = 20000 is " + pi*4);
12   } else if (i == 100000) {
13    System.out.println("Pi at i = 100000 is " + pi*4);
14   }
15 
16  }
17   System.out.println("Java's pi is " + Math.PI);
18 
19 }
20}
21
similar questions
queries leading to this page
programmingex5 25 java