Hey everybody, the program I am writing takes 10 digits as a floating point as a number then displays the average of the numbers and any numbers that are greater than it after it.
My program will compile but every time I run it through I get the error message
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10 at
avggrt.main(avggrt.java:44)
import TerminalIO.KeyboardReader;
public class avggrt
{
public static void main (String [] args)
{
KeyboardReader reader = new KeyboardReader();
double[] num = new double[10];
double[] pri = new double[10];
double[] grt = new double[10];
double number = 0.0;
double total = 0.0;
double rem = 0.0;
double ttotal = 0.0;
double avg = 0.0;
int cnum = 0;
int scnum = 0;
int fcnum = 0;
for (int i = 0;i < 10; i++)
{
System.out.print("Please Enter your Number: ");
number = reader.readDouble();
total = total + number;
num[cnum] = number;
cnum++;
}
avg = total / 10;
rem = total % 10;
ttotal = avg + rem;
for(int j = 0; j < cnum; j++)
{
if(num[scnum] > ttotal)
num[scnum] = grt[scnum];
scnum++;
{
for(int a = 1; a < 11; a++)
{
pri[fcnum] = grt[scnum];
fcnum++;
}
}
}
}
}
Thanks in advance.