Subato

SimpleArrayFuns

public final class SimpleArrayFuns {

  private SimpleArrayFuns() {
  }

  static boolean contains(int[] xs,int y){
    for (int x:xs){
      if (x==y)return true;
    }
    return false;
  }
  static long sum(int[] xs){
    long result = 0L;
    for (long x:xs){
      result += x;
    }
    return result;
  }
  static int avg(int[] xs){
    if (xs.length==0) return 0;
    return (int)(sum(xs)/xs.length); 
  }
  static boolean isSorted(int[] xs){
    int b = Integer.MIN_VALUE;
    for (int x:xs){
      if (x<b) return false;
      b = x;
    }
    return true;
  }
  static int max(int[] xs){
    int result = Integer.MIN_VALUE;
    for (int x:xs){
      if (x>result)result=x;
    }
    return result;
  }
}