Hi there,
I have to create a card game as an assignment, and i am having trouble with a part of the assignment.
Basically, there is an array, 'playerHand', which holds a set of integers. What i want to do is to add the elements of the array and then assign it an integer.
Here's what i have so far:
public static int scoreCalculator (int [] array, int howManyToAdd){ //user passes an array and the number of the index to which to add to. this method calculates the score
int score = 0; // the integer which holds the score
for (int count = 0; count <= howManyToAdd; count ++) //loops through each
score = score + array [count];
return score;
}
This is the error I am getting:
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
Thanks in advance :)