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

this is java problem. class named RecursionExamples with a number of empty metho

ID: 3698928 • Letter: T

Question

this is java problem. class named RecursionExamples with a number of empty methods corresponding to the 5 recursive methods described below. A main is provided for testing.

----------------------------------------------------------------------

public class RecursionExamples {

public static void main(String[] args) {

}

public static double sumSeries(int n) {

return 0.0;

// *** WRITE CODE HERE ***

}

public static void printReverse(String s, int n) {

// *** WRITE CODE HERE ***

}

public static void printReverse2(String s, int n) {

// *** WRITE CODE HERE ***

}

private static void printReverse2(String s, int n, int loc) {

// *** WRITE CODE HERE ***

}

public static int countDigits(String s, int low, int high) {

return 0;

// *** WRITE CODE HERE ***, can use helper, or not

}

public static int countCode(String msg, String code ) {

return 0;

// *** WRITE CODE HERE ***

}

private static int countCode(String msg, String code, int pos ) {

return 0;

// *** WRITE CODE HERE ***

}

}

a. Write a recursive method with this signature: public static double sumSeries(int n) that returns the sum of the series: 1 2 1 1 +--?i...-?, if i is even-, b. Write a recursive method with this signature (do not use a helper method): public static void printReverse (String s, int n) that prints tuples of size n from the string in reverse. Examples: Input' "3412",2 ("789456123".3)-- "7456123",3 ("abcdefghijklmnopqrstuvwxyz",10) Output 1234 123456789-+ 1234567+ qrstu hijklmnopabcdef* c. Write a method with this signature pub is static void printReverse2(String s, int n) {4 that utilizes this recursive helper method:

Explanation / Answer

Hi Please find my implementation of first function.

Please repost other in separate post.

public static double sumSeries(int n) {
      
       return sumSeries(n, 1);

   }
    // Helper Method
   public static double sumSeries(int n, int i) {

       if(i == n) {
           if(i%2 == 1)
               return 1.0/i;
           else
               return -1.0/i;
       }
      
       if(i%2 == 1)
           return 1.0/i + sumSeries(n, i+1);
       else
           return -1.0/i + sumSeries(n, i+1);

   }