Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if an integer is in a given range?

Hoping for something more elegant than

if (i>0 && i<100)  
like image 846
herpderp Avatar asked Apr 06 '11 23:04

herpderp


People also ask

How do you check if a number is within a range?

If x is in range, then it must be greater than or equal to low, i.e., (x-low) >= 0. And must be smaller than or equal to high i.e., (high – x) <= 0. So if result of the multiplication is less than or equal to 0, then x is in range.

How do you check if a number is within a range Java?

ValueRange. of(minValue, maxValue); range. isValidIntValue(x); it returns true if minValue <= x <= MaxValue - i.e. within the range.


1 Answers

You could add spacing ;)

if (i > 0 && i < 100)  
like image 65
Jakub Hampl Avatar answered Oct 09 '22 03:10

Jakub Hampl