In a Prediction Game, two or more players attempt to predict the score of a series of upcoming sporting competitions. Each player's predictions are then evaluated based on the sum of the categories listed below. These descriptions use the following variables:
S1: Actual score earned by team 1.
S2: Actual score earned by team 2.
P1: A player's predicted score for team 1.
P2: A player's predicted score for team 2.
but I have exception java.lang.ArrayIndexOutOfBoundsException
public void game() {
int s1, s2, p1, p2, winner, team1, team2, pointSpread, total = 0;
int testCase = scan.nextInt();
for (int k = 0; k < testCase; k++) {
int p = scan.nextInt();
int c = scan.nextInt();
int[]result = new int[p];
String[]pName = new String[p];
for (int i = 0; i < p; i++) {
pName[i] = scan.next();
for (int j = 0; j < c; j++) {
p1 = scan.nextInt();
p2 = scan.nextInt();
s1 = 20;
s2 = 13;
if (s1 > s2 && p1 > p2) {
winner = 10;
}
if (s1 < s2 && p1 < p2) {
winner = 10;
} else {
winner = 0;
}
team1 = 5 - Math.abs(s1 - p1);
team2 = 5 - Math.abs(s2 - p2);
pointSpread = 5 - Math.abs(p1 - p2)-(s1 - s2);
total += winner + team1 + team2 + pointSpread;
result[i] = total;
}
}
//compare players scores
int max = result[0], playerNo = 0;
for (int m = 1; m <= p; m++)//this line error
if (max < result[m]) {
max = result[m];
playerNo = m;
}
System.out.println(pName[playerNo]);
}
}