SHARE
TWEET

Untitled

a guest Mar 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class PiApprox {
  2.    
  3.     public static String iterPi2String(Double epsilon) {
  4.          // your code
  5.      System.out.println(epsilon);
  6.      System.out.printf("%f\n", epsilon);
  7.      long STOP = (long)(1.0d / epsilon);
  8.      System.out.println(STOP);
  9.      double sum = 1;
  10.      int den = 3;
  11.      for(long i = 1; i < STOP; i++){
  12.        if(i % 2 == 1){
  13.          sum -= (1.0 / (double)den);
  14.        }
  15.        else{
  16.          sum += (1.0 / (double)den);
  17.        }
  18.        den += 2;
  19.      }
  20.      String toReturn = "[" + STOP + ", ";
  21.      toReturn += String.format("%.10f", sum * 4);
  22.      toReturn += "]";
  23.      return toReturn;
  24.     }
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top