code: public static int clamp(int n, int min, int max) {
          if (n < min) return min;
          if (n > max) return max;
          return n;
      }
docs: Clamp an int to a min/max value.
  
  @param n     The value to be clamped
  @param min   The minimum
  @param max   The maximum
  @return      The value passed in, or minimum if n &lt; minimum, or maximum if n &gt; maximum