Here you can find the source of inRange(int n, int lo, int hi)
Parameter | Description |
---|---|
n | The number to be checked |
lo | The Lower margin of the number. n cannot be smaller than this |
hi | The Upper margin of the number. n cannot be bigger than this |
public static int inRange(int n, int lo, int hi)
//package com.java2s; //License from project: Open Source License public class Main { /**// w w w . ja v a 2 s . c o m * Avoid a number getting out of a certain range * @param n The number to be checked * @param lo The Lower margin of the number. n cannot be smaller than this * @param hi The Upper margin of the number. n cannot be bigger than this * @return If n is out of range, set to defined extreme values, otherwise return n */ public static int inRange(int n, int lo, int hi) { return n < lo ? lo : (n > hi ? hi : n); } /** * Avoid a number getting out of a certain range * @param n The number to be checked * @param lo The Lower margin of the number. n cannot be smaller than this * @param hi The Upper margin of the number. n cannot be bigger than this * @return If n is out of range, set to defined extreme values, otherwise return n */ public static double inRange(double n, double lo, double hi) { return n < lo ? lo : (n > hi ? hi : n); } }