kittylove650 kittylove650
  • 17-09-2018
  • Computers and Technology
contestada

Implement a recursive java method to find the sum of the first n int's in a java int array. Max size 20.

Respuesta :

Helsset Helsset
  • 28-09-2018

Solution:

public class SumOfArray {

private int[] a;

private int n;

private int result;

   public int sumOfArray(int[] a,int n) {

     this.a = a;//Max size is 20

     n = a.length;

     if (n == 0)  // base case

     return a[n];

     else

         return a[n] + sumOfArray(a, n-1);

     return result;

  } // End SumOfArray method

} // End SumOfArray Class  


Answer Link

Otras preguntas

If a cow has a mass of 9×102 kilograms, and a blue whale has a mass of 1.8×105 kilograms, which of these statements is true?
hello whats is the size of the angle
Find the range from the ordered pair {(1, 0), (2, -1), (3, -2), (4, -3)}.
does anyone know the answer!!
Please help I need help Solve for x. Assume that lines which appear tangent are tangent. Find VT
sterility disease caused by?​
A box of mass 4.5 kg is pushed across a rough surface (μK = 0.18) for a distance of 2.0 m by a constant force of 10 N. If the object reaches a speed of 2.0 m/s
f 4 adult females are randomly​ selected, find the probability that they have pulse rates with a mean less than 81 beats per minute.
One way states can support a fair election process is to make voting mandatory for all citizens. train poll workers adequately. allow only educated individuals
which of these figures does NOT have line symmetry​