I have a program that I am trying to do for a class that returns the sum of all integers in an array using recursion. Here is my program:
public class SumOfArray { private int[] a; private int n; private int result; public int sumOfArray(int[] a) { this.a = a; n = a.length; if (n == 0)
But I get three errors that are all related, I suppose, but I can't figure out why it finds a null type:
SumOfArray.java:25: sumOfArray(int[]) in SumOfArray cannot be applied to (int) result = a[n] + sumOfArray(a[n-1]); ^ SumOfArray.java:25: operator + cannot be applied to int,sumOfArray result = a[n] + sumOfArray(a[n-1]); ^ SumOfArray.java:25: incompatible types found : <nulltype> required: int result = a[n] + sumOfArray(a[n-1]); ^ 3 errors
source share