Here you can find the source of clamp(int n, int lower, int upper)
Parameter | Description |
---|---|
n | value |
lower | lower limit |
upper | upper limit |
public static int clamp(int n, int lower, int upper)
//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)); } }