Java Integer Clamp clamp(int n, int lower, int upper)

Here you can find the source of clamp(int n, int lower, int upper)

Description

Limit the value n between lower and upper

License

Apache License

Parameter

Parameter Description
n value
lower lower limit
upper upper limit

Return

the value n clamped

Declaration

public static int clamp(int n, int lower, int upper) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Apache License Version 2.0//from   w  ww . j ava 2  s .com
 *
 * Saul de Nova Caballero
 ******************************************************************************/

public class Main {
    /**
     * Limit the value n between lower and upper
     * @param n value
     * @param lower lower limit
     * @param upper upper limit
     * @return the value n clamped
     */
    public static int clamp(int n, int lower, int upper) {
        return Math.max(lower, Math.min(n, upper));
    }
}

Related

  1. clamp(int i, int low, int high)
  2. clamp(int i, int min, int max)
  3. clamp(int min, int val, int max)
  4. clamp(int min, int value, int max)
  5. clamp(int n, int l, int u)
  6. clamp(int n, int min, int max)
  7. clamp(int n, int min, int max)
  8. clamp(int num, int min, int max)
  9. clamp(int number, int low, int high)