I'm in an Intro to programming class, and I'm really having trouble with variable scope and loops. Here's my loop:
import java.util.Scanner;
public static void scoreAverages(int players, int games)
{
Scanner keyboard = new Scanner(System.in);
int playerAverage;
int teamScoreAccumulator = 0;
int teamScoreAverage;
for(int x = 1; players >= x; x++)
{
int scoreAccumulator = 0;
for(int y = 1; games >= y; y++)
{
System.out.println("Enter score " + y +" for player " + x + ": ");
scoreAccumulator = scoreAccumulator + keyboard.nextInt();
}
teamScoreAccumulator = teamScoreAccumulator + scoreAccumulator;
playerAverage = scoreAccumulator / games;
System.out.println("Player " + x + " average: " + playerAverage);
}
teamScoreAverage = teamScoreAccumulator / (games * players);
System.out.println("Team average: " + teamScoreAverage);
}
}
I need to get it to somehow store the individual averages outside of the loop, because I have to determine who has the highest average. Any tips?


