Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is topology? Explain with examples

Answered: 1 week ago

Question

Is this investment worthwhile? Why or why not?

Answered: 1 week ago