fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static int suma = 0;
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. int[] nums = { 3, 9, 7, 12, 20, 4, 11, 9, 21, 6, 8, 10 }; //{3, 9, 7, 12, 20, 4, 11, 9, 21, 6, 8, 10};
  14. System.out.println(average(nums, 0));
  15. }
  16.  
  17. public static int average(int n[], int pos){
  18. //float resultado = (float)suma /(float)n.length;
  19. if(pos < n.length) {
  20. suma = suma + n[pos];
  21. average(n, pos + 1);
  22. //System.out.println(resultado);
  23. }
  24. //return resultado;
  25. //return (float)suma/ (float)n.length;
  26. return suma;
  27.  
  28. }
  29.  
  30. }
Success #stdin #stdout 0.06s 32340KB
stdin
Standard input is empty
stdout
120