Ask Question

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

+3
Answers (1)
  1. 4 September, 04:06
    0
    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
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Implement a recursive java method to find the sum of the first n int's in a java int array. Max size 20. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers