Advertisement
fatalryuu

Untitled

Sep 28th, 2022
810
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. package com.company;
  2.  
  3. //p/8 = 1/1*3 + 1/5*7 - 1/9*11+...
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         final double e = 0.0000000000001;
  8.         int i = 1;
  9.         double p0 = 0;
  10.         double p1 = 0;
  11.         double sum = 0;
  12.         do {
  13.             p1 = p0;
  14.             p0 = (double) 1 / (i * (i + 2));
  15.             sum += p0;
  16.             i += 4;
  17.         } while (Math.abs(p1 - p0) > e);
  18.         System.out.println(sum * 8);
  19.     }
  20. }
  21.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement