I don't know why it throws the exception any ideals??
heres my error: the line it tells me is throwing the exception is highlighted in red:
run:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at lab32analyzingscores.Main.main(Main.java:15)
Java Result: 1
BUILD SUCCESSFUL (total time: 11 seconds)
package lab32analyzingscores;
import javax.swing.JOptionPane;
/**
*
* @author Joe
*/
public class Main {
public static void main(String[] args) {
double[] score = new double[4];
double sum = 0;
int count = 0;
do {
String scoreString = JOptionPane.showInputDialog(null, "Enter a new score");
score[count] = Double.parseDouble(scoreString);
sum += score[count];
}
while (score[count++] >= 0);
double average = (sum - score[count]) / (score[count] - 1);
int numOfAbove = 0;
int numOfBelow = 0;
for (int i = 0; i < count -1; i++)
if (score[i] >= average)
numOfAbove++;
else
numOfBelow++;
System.out.println("Average is " + average);
System.out.println("Number of scores above or equal to the average " + numOfAbove);
System.out.println("Number of scores below the average " + numOfBelow);
}
}