So ive been trying to get an average of this array needed, and I seem to be having trouble with it. So far, my current code just adds the numbers up, but doesnt really average them out at all:
import java.util.Scanner;
import java.util.Arrays;
public class Grades {
public static void main (String[] args)
{
double result = 0;
Scanner scan = new Scanner(System.in);
float[] grades = new float[100];
for (int i = 0; i < grades.length; i++) {
System.out.print("Enter a grade between 0.0 - 100.0 (enter -1 to quit): ");
grades[i] = scan.nextFloat();
if(grades[i] == -1)break;
result = result + grades[i];
}
System.out.println("Average of Grades: " + result / grades.length);
}
}
and the result is as follows:
Enter a grade between 0.0 - 100.0 (enter -1 to quit): 30.0
Enter a grade between 0.0 - 100.0 (enter -1 to quit): 50.0
Enter a grade between 0.0 - 100.0 (enter -1 to quit): 60.0
Enter a grade between 0.0 - 100.0 (enter -1 to quit): -1
Average of Grades: 1.4
any help would be appreciated.