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

Kelly carried a box weighing 10 N the 200 meters from his car to his new house.  George took the box from Kelly and carried it up the 3 meter tall flight of sta
when does an inciting incident occur in a plot?
G=H(q+Q)for Q Solve for Q I dont understand how to do this.
Kelly carried a box weighing 10 N the 200 meters from his car to his new house.  George took the box from Kelly and carried it up the 3 meter tall flight of sta
G=H(q+Q)for Q Solve for Q I dont understand how to do this.
Give Reason:- 1)Vegetables release water after salt is added to them 2) Nucleus is absent in red blood cells 3) The skin of your fingers shrinks when you wash
If p+q+r = 1 and pq+qr+pr = -1, and pqr = -1, find the value of [tex] p^{3}+ q^{3}+ r^{3} [/tex]
An automobile engine exerts a force of 595 N to propel the car at 90.0 km/h on a level road.  What is the power output of the engine at that time?
what is the KE of a 1 kg ball traveling at 30 meters per second?
when does an inciting incident occur in a plot?