Ad

The classic average.

Code
Diff
  • import java.util.*;
    public class Average {
       public static int averageFinder(int[] arr) {
         if (arr.length == 0)
           return 0;
         
         int out = 0;
         
         for (int i : arr)
           out += i;
         
         return out/arr.length;
       };
    }
    • import java.util.*;
    • public class Average {
    • public static int averageFinder(int[] arr) {
    • return (int)Arrays.stream(arr).average().orElse(0d);
    • if (arr.length == 0)
    • return 0;
    • int out = 0;
    • for (int i : arr)
    • out += i;
    • return out/arr.length;
    • };
    • }