Hello helper Question Write a program that recursively calculates the following
ID: 3681902 • Letter: H
Question
Hello helper Question Write a program that recursively calculates the following series: m(i) = 1 + 4 + 6 + _8 + … + __2i__ 5 8 11 3i - 1
Write a test program that demonstrates the procedure for i = 1 to 10 using a loop. This from Intro to Java Programing breif version 10th Edition In chapter 18 Recursion . I need the answer as soon as possible .
Thanks
Write a program that recursively calculates the following series: 1 +4 +6 8+ .2i 5 8 11 3i -1 Write a test program that demonstrates the procedure for i = 1 to 10 using a loop.Explanation / Answer
public class SeriesSum {
// this method will take i value and return sum of series up to ith terms.
public static double seriesSum(int i){
double sum = 0; // initializing sum
for(int j=1; j<=i; j++){ // from 1 to i
sum = sum + ((double)(2*j))/(3*j-1);
}
return sum;
}
public static void main(String[] args) {
// testing seriesSum method with i value from 1 to 10
for(int i=1; i<=10; i++){
double sum = seriesSum(i);
System.out.println("Sum of first "+i+" terms of series: "+String.format("%.3f", sum));
}
}
}
/*
Sample Run:
Sum of first 1 terms of series: 1.000
Sum of first 2 terms of series: 1.800
Sum of first 3 terms of series: 2.550
Sum of first 4 terms of series: 3.277
Sum of first 5 terms of series: 3.992
Sum of first 6 terms of series: 4.697
Sum of first 7 terms of series: 5.397
Sum of first 8 terms of series: 6.093
Sum of first 9 terms of series: 6.785
Sum of first 10 terms of series: 7.475
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.