code to explanationSun, 26 Mar 2023

Write a program to calculate the result of the formula pi in java πœ‹=4(1βˆ’1/3+1/5βˆ’1/7+1/9βˆ’1/11+1/13βˆ’β‹―βˆ’1/2π‘–βˆ’1+1/2𝑖+1) with 10000 ≀ i ≀ 100000

public class pi { public static void main(String[] args) { double pi = 4; double i = 3; double precision = 0.00000001; double result = 0; for (i = 3; i < 100000; i += 2) { double k = (double) 1 / i; if (i % 4 == 1) { pi = pi - k; } else { pi = pi + k; } result = pi; } System.out.println(result); } }

Questions about programming?Chat with your personal AI assistant