Ask Question
5 April, 02:34

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

+5
Answers (1)
  1. 5 April, 02:44
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers