- #1
Ajmather
- 2
- 0
I am attempting to find the numbers above the average number of a set of numbers in an array. I am having trouble understanding why my output for the list of numbers above the average is so...weird. I'd appreciate the help!
My code:
My output:
My code:
Code:
public class Inequality
{
public static void main(String[] args)
{
// list of incomes in thousands
int[] income = {2,10, 532, 4, 53, 28, 291, 38, 6, 17, 73, 21};
int sum = 0;
int average;
int aboveAverage = 0;
for (int i = 0;i< income.length;i++)
{
sum = sum + income[i];
}
average = sum/income.length;
System.out.println("Average of income array: " + average);
for (int i = 0; i < income.length; i++)
{
if (income[i]>average)
{
aboveAverage++;
}
}
System.out.println("There are " + aboveAverage + " numbers above the average.");
System.out.println("Range of numbers above the average: " + income);
}
}
My output:
Code:
Average of income array: 89
There are 2 numbers above the average.
Range of numbers above the average: [I@15db9742