I would like to design a method which when given an array it returns an array which it's elements are from the initial array greater than the average of all numbers in that array;
the method average(int array[]) works properly here is the problem
here is that method
Your reply will be appreciated
the method average(int array[]) works properly here is the problem
here is that method
Code:
public static int[] small(int array[]){
double s1 = average(array);
int length = 0;
//Finds how many numbers are greater than the average
for(int j:array){
if (j > s1){
length++;
}
}
int initial = 0;
int array2[] = new int[length];
void add(int p){
array2[initial] = p;
initial++;
}
for (int j:array){
if (j > s1)
array2.add(j);
}
return array2;
}
Comment