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

Java Please specify each part in your code Part 1 Trace the execution of the fol

ID: 3589257 • Letter: J

Question

Java

Please specify each part in your code

Part 1

Trace the execution of the following method by listing what is printed when the method is invoked with the following parameters:

array = [12, 5, 6, 2, 3, 4, 7]

a=2

b=5

void recMethod(int[] array, int a, int b) {

if(b > a) {

print the array

double the value in the array at position b

recMethod(array, a, b-1)

print the array

} else {

print "done"

}

}

Part 2

Trace the execution of the following method by listing what is printed when the method is invoked with the first node in the following chain: 4 -> 6 -> 5 -> 3 -> 2

void recMethod(Node firstNode) {

print the chain of nodes headed by firstNode

if(firstNode.next!=null) {

double the data in firstNode

recMethod(firstNode.next.next);

} else {

print "done"

}

print the chain of nodes headed by firstNode

}

Explanation / Answer

class Main{
static void recMethod(int[] array, int a, int b)
{
    if(b>a)
    {
      for(int i=0;i<array.length;i++)
        System.out.printf("%d ",array[i]);
      System.out.println(" ");
      array[b] = array[b]*2;
      recMethod(array, a, b-1);
    }
    else
    {
      System.out.println("Done");
    }
}

public static void main(String[] args)
{
    int a[]={12, 5, 6, 2, 3, 4, 7};
    recMethod(a, 2, 5);
}
}

  PART1 OUTPUT    12 5 6 2 3 4 7     12 5 6 2 3 8 7     12 5 6 2 6 8 7     Done  

class Main{
static void recMethod(int[] array, int a, int b)
{
    if(b>a)
    {
      for(int i=0;i<array.length;i++)
        System.out.printf("%d ",array[i]);
      System.out.println(" ");
      array[b] = array[b]*2;
      recMethod(array, a, b-1);
    }
    else
    {
      System.out.println("Done");
    }
}

public static void main(String[] args)
{
    int a[]={12, 5, 6, 2, 3, 4, 7};
    recMethod(a, 2, 5);
}
}

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