Made a couple of silly mistakes. The working code below.
Thanks.
public class Methods {
public int counts(int[] array)
{
int sum = 0;
int count = 0;
for (int i = 0; i < array.length; i++)
{
sum = sum + array[i];
}
double average = sum/array.length;
for (int i = 0; i < array.length; i++) {
if (array[i] > average)
{
count++;
}
}
return count;
}
}
public class Main {
public static void main(String[] args) {
int[] array1 = {1,4,6,2,4,7,8,9};
Methods m1 = new Methods();
int result = m1.counts(array1);
System.out.println("Numbers above the average: " +result);
}
}