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

68 goes into 481 how many. times in rounding
What can happen if DNA is not copied correctly
Athens was on which of the following continents??? a) Greece b) Italy c) Europe d) Peloponnesus
the water pipe has a radius of 5 cm and a height of 7 cm. What volume of water does it take to fill the pipe
Why are spaces left between sections of a bridge
Why are spaces left between sections of a bridge
Each container holds 1 L 275 mL of water.how much water is in 609 identical containers find the difference between your estimated product and precise product
A recipe for cookies calls for 3 1/4 cups of sugar. Amy has already put in 3 1/9 cups. How many more cups does she need to put in?
I NEED HELP ASAP Do your body cells always use cellular respiration to break down glucose?
What is the value of the expression 3/3^-2