Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Time Error - Method not Found

Status
Not open for further replies.

jeak

Technical User
Oct 9, 2002
16
US
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(&quot;Value at index &quot; + i + &quot; = &quot;
+ testArray);
int sum = sumOfInts(testArray);
System.out.println(&quot;&quot;);
System.out.println(&quot;The sum should be 75&quot;);
System.out.println(&quot;The actual sum returned is &quot; + 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;
}
}
}


 
int sum = sumOfInts(testArray);

in your main is an argument short of a full set: it needs to conform to your method prototype:

public static int sumOfInts(int[] array, int index)

and have an index passed to it as an arg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top