Returns true if and only if the given value is between value1 and value2. - Java java.lang

Java examples for java.lang:double

Description

Returns true if and only if the given value is between value1 and value2.

Demo Code


//package com.java2s;

public class Main {
    /**//w w  w .  j av a2  s.  c o m
     * Returns true if and only if the given value is between value1 and value2. It doesn't matter 
     * if value1 is bigger than value2 or vica-versa.
     * 
     * @param value the value to be checked
     * @param value1 the border of the interval
     * @param value2 the border of the interval.
     * @return  true if and only if the given value is between value1 and value2
     */
    public static boolean between(double value, double value1, double value2) {
        return (value1 <= value && value <= value2)
                || (value2 <= value && value <= value1);
    }
}

Related Tutorials