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

Mosaics were common in Pompeii because they were very easy to make. True False
what happens if i take to allertec pills in 24 hours(health question)
Which type of essay is Amy Tan's "Mother Tongue"? A)persuasive B)regional C)bias D)reflective
What is the central conflict in the story "Two Kinds" by Amy Tan? mother's wishes vs. daughter's will Jing-mei vs. Old Chong Suyuan vs. Old Chong Waverly vs. Ji
3.In "My Father Is a Simple Man," what do the lines "and when the bitter-hard reality / comes at me like a punishing / evil stranger" contain? A. a rhyming cou
the best description of a propriety database
The political party symbol that emerged when cartoonists mocked Andrew Jackson
what is formed when an overly grows larger
How will the movement of water affect a cell if it is transferred from a hypotonic solution to a hypertonic solution?
which sentence uses correct punctuation? A. Steve suggested Italian sausages, Dan didn't like that idea at all. B.Steve suggested Italian sausages; Dan didn