I am getting the following run-time error when I try to run the program below. "sumOfInts.java": Error #: 300 : method sumOfInts(int[]) not found in class sumOfInts at line 24, column 20
Does anyone have any suggestions on what I am doing wrong?
public class sumOfInts
{
public static void main(String[] args)
{
int[] testArray = new int[5];
testArray[0] = 5;
testArray[1] = 8;
testArray[2] = 42;
testArray[3] = 1;
testArray[4] = 19;
System.out.println("The integers in the array are:"
for(int i = 0; i < testArray.length; i++)
System.out.println("Value at index " + i + " = "
+ testArray);
int sum = sumOfInts(testArray);
System.out.println(""
System.out.println("The sum should be 75"
System.out.println("The actual sum returned is " + sum);
}
public static int sumOfInts(int[] array, int index) {
int sum = 0;
if( index < array.length ){
return array[index] + sumOfInts(array, index+1);
}
else{
return 0;
}
}
}
Does anyone have any suggestions on what I am doing wrong?
public class sumOfInts
{
public static void main(String[] args)
{
int[] testArray = new int[5];
testArray[0] = 5;
testArray[1] = 8;
testArray[2] = 42;
testArray[3] = 1;
testArray[4] = 19;
System.out.println("The integers in the array are:"
for(int i = 0; i < testArray.length; i++)
System.out.println("Value at index " + i + " = "
+ testArray);
int sum = sumOfInts(testArray);
System.out.println(""
System.out.println("The sum should be 75"
System.out.println("The actual sum returned is " + sum);
}
public static int sumOfInts(int[] array, int index) {
int sum = 0;
if( index < array.length ){
return array[index] + sumOfInts(array, index+1);
}
else{
return 0;
}
}
}