Question: JAVA PROGRAMMING! Create a Java program. The class name for the program should be 'CalculatePI'. In the main method you should perform the following: 1.Create

JAVA PROGRAMMING!

  1. Create a Java program.
  2. The class name for the program should be 'CalculatePI'.
  3. In the main method you should perform the following:
    • 1.Create a for loop that will loop for 10,000,000 iterations that will be used to calculate the Mathematical value of PI.
    • 2.You will need a variable to count the iterations.
    • 3.You will need a variable that will be used in the mathematical calculation inside the loop.
    • 4.The formula for PI is: PI = 4 * (1 - 1/(2*i-1) + 1/(2*i+1) . . .
    • 5.Each 1000th iteration of the loop should print the iteration number and the currently calculation for PI.
    • 6.At the end of the loop the program should display the value of PI as determined by the variable Math.PI and the difference between your calculated value and the value contained in Math.PI
    • 7.You should then repeat the instructions above using a while( ) loop rather than a for( ) loop.

Follow these Tips for this assignment.

  1. Create a variable to contain the PI calculation. The initial value of this variable should be 1.
  2. Create a for( ) loop that will loop for 10,000,000 iterations. You will need a loop variable to count the number iterations.
  3. Create a second loop variable that will be used for i in the calculation. The initial value of this varaible should be 2.
  4. For each iteration of the loop you will need to subtract the value of 1.0/(2*i-1) from the calculation and add the value of 1.0/(2*i+1).
  5. At the end of the loop you will increment the iteration loop variable by 1 and increment the value of i used in the calculation by 2.
  6. Every 1000th iteration of the loop you should display the iteration number and the calculated value for PI.
  7. When you have completed the loop you should print the value of Math.PI and the difference between Math.PI and your calculated value of PI.
  8. You will then repeat this process using a while( ) loop.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!