public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of iterations: "); double NumOfIterations1 = input.nextInt(); int odd=1; double pi=0.0; for (int i = 1; i <= NumOfIterations1; i++) { double currentTerm; if (i%2==0) { currentTerm=(double)-4/odd; } else { currentTerm=(double)4/odd; } odd=odd+2; pi=pi+currentTerm; } double NumOfIterations2 = input.nextInt(); for (int i = 1; i <= NumOfIterations2; i++) { double currentTerm2; if (i%2==0) { currentTerm2=(double)-4/odd; } else { currentTerm2=(double)4/odd; } odd=odd+2; pi=pi+currentTerm2; } double NumOfIterations3 = input.nextInt(); for (int i = 1; i <= NumOfIterations3; i++) { double currentTerm3; if (i%2==0) { currentTerm3=(double)-4/odd; } else { currentTerm3=(double)4/odd; } odd=odd+2; pi=pi+currentTerm3; } System.out.println("The value of pi is: " + pi + " when i = " + NumOfIterations1); System.out.println("The value of pi is: " + pi + " when i = " + NumOfIterations2); System.out.println("The value of pi is: " + pi + " when i = " + NumOfIterations3); } }

***** EDIT *****

Please use code tags when posting code!

This post has been edited by **GunnerInc**: 15 October 2013 - 07:26 PM

Reason for edit:: Added code tags