Omar_Natour

Natour, O. 10/16/15 Csc-111-D01 Hw 5.25

Oct 16th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. /*
  2.  * Omar Natour
  3.  * 10/16/2015
  4.  * Csc-111-D01
  5.  * Problem 5.25
  6.  * Compute the value of pie.
  7.  */
  8.  
  9. public class Homework5 {
  10.     public static void main(String[] args) {
  11.        
  12.         for (int counter = 10000; counter <= 100000; counter += 10000) {
  13.             System.out.print("value of pi when i = " + counter + " : ");
  14.            
  15.             double pie = 0;
  16.             double div = 1;
  17.  
  18.             for (int i = 0; i < counter; i++) {
  19.  
  20.                 if (i % 2 == 0)
  21.                     pie = pie + 1 / div;
  22.                 else
  23.                     pie = pie - 1 / div;
  24.                 div += 2;
  25.             }
  26.             System.out.println(pie * 4);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment