Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

18.4 (Sum series) Write a recursive method to compute the following series: m(i)

ID: 3818516 • Letter: 1

Question

18.4 (Sum series) Write a recursive method to compute the following series:

m(i)= 1 + 1/2 + 1/3 + ... + 1/i

Write a test program that displays m(i) for i = 1, 2, . . ., X each on it's line and where X is entered by the user.

output most look like this

Enter the last positive integer you .want .m (i).to be calculated for 23 m(1) 1.00 H J m(2) 1.50 m(3) 1.83 m(4) 2.08 m (5) 2.28 H m(6) 2.45 J (7) 2.59 J m m(8) 2.72 m(9) 2.83 m(10) 2.93 m (11) 3.02 (12) 3.10 m(13) 3.18 m(14) 3.25 m (15) 3.32 m(16) 3.38 (17) 3.44 m(18) 3.50 m (19) J. 3.55 (20) 3.60 m(21) 3.65 m(22) 3.69 (23) 3.73

Explanation / Answer

import java.util.*;

public class Sum{

static double sumSeries(int i)
{
if(i==1)
return 1; //Base condition
else
{
double check = 1/i;
return check + sumSeries(i-1);
  
}
}
public static void main(String []args){
  
double result;
int n;
Scanner s = new Scanner(System.in);
System.out.println("Please enter the last positive integer you want m(i) to be calculated for");
n = s.nextInt();
  
result = sumSeries(n);
  
System.out.println("sum of the series is" + result);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote