I am using the (List) java structure:
var nums = List.of( 3, 9, 7, 12, 20, 4, 11, 9, 21, 6, 8, 10 );
Through that use, I am performing the following program without the need to use repetitive cycles:
package averagesumwithoutcycles;
import java.util.*;
import java.util.List;
public class SumaSinCiclos {
private static int suma = 0;
public static void main(String[] args) {
int[] nums = {3, 9, 7, 12, 20, 4, 11, 9, 21, 6, 8, 10};
System.out.println(average(nums, 0));
}
public static float average(int n[], int pos){
float resultado = (float)suma /(float)n.length;
if(pos < n.length) {
suma = suma + n[pos];
average(n, pos + 1);
System.out.println(resultado);
}
return resultado;
}
}
So far I have achieved the following:
- Sum of the Array elements
- Number of elements in the Array
- Division Result (Average)
My question is the following, based on my code, how can I sum the elements (array), calculate the average, and filter those elements that are less than the average.
Note: It is important to obtain this data without using repetitive cycles