Ad

Array may be empty.

Code
Diff
  • import java.util.*;
    public class Average {
       public static int averageFinder(int[] arr) {
         return  (int)Arrays.stream(arr).average().orElse(0d);
       };
    }
    • import java.util.*;
    • public class Average {
    • public static int averageFinder(int[] arr) {
    • return (int)Arrays.stream(arr).average().getAsDouble();
    • return (int)Arrays.stream(arr).average().orElse(0d);
    • };
    • }