Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java chained inequality if (5<i<10)

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

if(5<i && i<10)

?

like image 667
Whimusical Avatar asked May 18 '12 19:05

Whimusical


People also ask

Can you chain inequalities in Java?

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. Perhaps the parameters should be ordered as isInRange(low, value, high) e.g. isInRange(5, i, 10) .

How do you write an inequality in Java?

Inequality. The inequality operator is != (an exclamation point, followed by an equal sign). It is a binary operator: exprleft !=


1 Answers

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.

like image 148
Gyscos Avatar answered Oct 23 '22 02:10

Gyscos