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

Java_problem a) Create a recursive static method called summation that will take

ID: 3569126 • Letter: J

Question

Java_problem

a) Create a recursive static method called summation that will take in 2 parameters of type int and return the sum of all of the numbers from the 1st number to the 2nd number (including the 1st and last number). Assume the 1st parameter is less than or equal to the 2nd parameter.

b) Create another method called summation2, which does the same thing as summation except that the 1st parameter could be less than the 2nd.

2)

a) Create a recursive method in class Node. Call it partialSum. The method should return the sum of the data value of Node the method was called on and the sum of the data values of all of the Nodes after it in the LinkedList. For example, if the values in the nodes in the list are 1 through 13, and method partial sum is called on the 7th node, the method should return 70.

b)NOTE: for this part you will be creating 2 methods that have the same name, but they will be defined in different classes. make sure that you do not comfuse them.

Create a method in class LinkedList called printBack(), this method should call method printBack() on its head variable. Create method printBack() in class Node. This method should output to the console in reverse order the data values in each node from the last node in the list until the current node. So, for the example in part 2a, the output should look like:

13 12 11 10 9 8 7

Explanation / Answer

// Method
public static int[] summation(int a, int b)// returning array
{
   sum=0;
   for(int i=a; i<=b; i++)
   {
       sum=sum+i;
   }
   //summation(a,b) this code can be used to call the method from itself
   return(sum,a,b);
}

// Method
public static int[] summation2(int a, int b)// returning array
{
   sum=0;
   if(a<b)
   {
   for(int i=a; i<=b; i++)
   {
       sum=sum+i;
   }
   return(sum,a,b);
   }
   else return 0;
}

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