Generation

regex 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 PiCalculation { public static void main(String[] args) { Scanner input= new Scanner(System.in); System.out.println("Please enter a number:"); int i=input.nextInt(); double pi=0.0; while (i<=100000) { if (i%2==0) { pi = pi + (1 / (2 * i + 1)); i++; } else { pi = pi - (1 / (2 * i + 1)); i++; } } pi=pi*4; System.out.println("The result is:"+pi); } }

Questions about programming?Chat with your personal AI assistant