Java chained inequality if (5<i<10)

Whimusical picture Whimusical · May 18, 2012 · Viewed 8k times · Source

Is there any operator or trick for such operation? Or is it necessary to use

if(5<i && i<10)

?

Answer

Gyscos picture Gyscos · May 18, 2012

You cannot chain inequalities. You can, however, define a static boolean method isInRange(value, low, high) that will perform such a check.

Some other languages, like Python or Icon, allow this notation.