Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- //p/8 = 1/1*3 + 1/5*7 - 1/9*11+...
- public class Main {
- public static void main(String[] args) {
- final double e = 0.0000000000001;
- int i = 1;
- double p0 = 0;
- double p1 = 0;
- double sum = 0;
- do {
- p1 = p0;
- p0 = (double) 1 / (i * (i + 2));
- sum += p0;
- i += 4;
- } while (Math.abs(p1 - p0) > e);
- System.out.println(sum * 8);
- }
- }
Advertisement
Advertisement