Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Calculus { public static double pi ( int n ) { double result = 3 . 4 6 4 1 0 1 6

public class Calculus {
public static double pi(int n){
double result =3.4641016151377544; // Start with 3.4
for (int i =1; i = n; i++){
result += Math.pow(-1, i)/(2.0* i +1.0); // Fixed the denominator
System.out.println("Pi value after "+ i +" term(s)="+ result);
}
return result *3; // Removed the multiplication by 4
}
public static double euler(int n){
double result =1.0;
double term =1.0;
for (int i =1; i n; i++){
term /= i;
result += term;
}
return result;
}
public static void main(String[] args){
for (int i =1; i =30; i++){
pi(i); // Call pi method to print each line
}
for (int i =1; i =18; i++){
System.out.println("Euler value after "+ i +" term(s)="+ euler(i));
}
}
} make sure it prints this based of my code above don't change the methods up too much please just fix the formula for pi so that it print the lines below exactly please make sure it's correct I'll like Pi value after 1 term(s)=3.4641016151377544
Pi value after 2 term(s)=3.0792014356780038
Pi value after 3 term(s)=3.156181471569954
Pi value after 4 term(s)=3.1378528915956805
Pi value after 5 term(s)=3.1426047456630846
Pi value after 6 term(s)=3.141308785462883
Pi value after 7 term(s)=3.1416743126988376
Pi value after 8 term(s)=3.141568715941784
Pi value after 9 term(s)=3.141599773811506
Pi value after 10 term(s)=3.1415905109380797
Pi value after 11 term(s)=3.1415933045030813
Pi value after 12 term(s)=3.1415924542876463
Pi value after 13 term(s)=3.14159271502038
Pi value after 14 term(s)=3.141592634547314
Pi value after 15 term(s)=3.141592659521714
Pi value after 16 term(s)=3.1415926517339976
Pi value after 17 term(s)=3.1415926541725754
Pi value after 18 term(s)=3.141592653406165
Pi value after 19 term(s)=3.1415926536478262
Pi value after 20 term(s)=3.1415926535714034
Pi value after 21 term(s)=3.141592653595635
Pi value after 22 term(s)=3.1415926535879337
Pi value after 23 term(s)=3.1415926535903864
Pi value after 24 term(s)=3.1415926535896035
Pi value after 25 term(s)=3.141592653589854
Pi value after 26 term(s)=3.141592653589774
Pi value after 27 term(s)=3.1415926535897998
Pi value after 28 term(s)=3.1415926535897913
Pi value after 29 term(s)=3.141592653589794
Pi value after 30 term(s)=3.1415926535897936
image text in transcribed

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

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

Explain the need for remedial basic skills training programs

Answered: 1 week ago

Question

Describe a typical interpersonal skills training program

Answered: 1 week ago