I'm writing a program for a java course i'm taking, I am to set up an array that reads in (input from user or not, i've no idea because it's not specified so I assume not) - I have everything working fine, except when I run the program i'm getting this output...
Height 0 = 140
Height 1 = 130
Height 2 = 132
Height 3 = 154
Height 4 = 200
Height 5 = 201
Height 6 = 190
Height 7 = 182
Height 8 = 123
Height 9 = 167
Your average is: 161
Above average: [I@fd54d6
Above average: [I@fd54d6
Above average: [I@fd54d6
Above average: [I@fd54d6
Above average: [I@fd54d6
java.lang.ArrayIndexOutOfBoundsException
at Heights.main(Heights.java:24)
The top part is correct, including the average - but the above average part isn't = [, I can't seem to fix it either. Sorry for the denseness.
Here's my code.
Code:
// The "Heights" class.
public class Heights
{
public static void main (String [] args)
{
// declare , initialize array
int avg;
int total = 0;
int [] heightsArray = {140, 130, 132, 154, 200, 201, 190, 182, 123, 167};
// print heights
for (int i = 0 ; i < 10 ; i++)
{
System.out.println ("Height " + i + " = " + heightsArray [i]);
total += heightsArray [i];
}
avg = total / 10;
System.out.println ("Your average is: " + avg);
int numOfAbove = 0;
int count = 0;
for (int i = 0 ; i < avg ; i++)
{
if (heightsArray [i] > avg)
System.out.println ("Above average: " + heightsArray);
}
} // main method
} // Heights class
Any and all help is appreciated, and will be credited in my program.