Share the post "Check If Number Is Between Two Numbers Using Java"

This method returns true if a number is between a number range.

1 2 3 4 |
// Return true if c is between a and b. public static boolean isBetween(int a, int b, int c) { return b > a ? c > a && c < b : c > b && c < a; } |

If you want to use **float** or** double** values, you can use the same method and replace the **int** data type to either a** float** or **double**.

why so difficult?

boolean isBetween(int a, int b, int c) {

return a >= b ? a <= c : false;

}