Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Greater than and less than in one statement

Tags:

I was wondering, do you have a neat way of doing this ?

if(orderBean.getFiles().size() > 0  && orderBean.getFiles().size() < 5)

without declaring a variable that is not needed anywhere else ?

int filesCount = orderBean.getFiles().size();
if(filesCount > 0  && filesCount < 5) {

I mean, in for loop we are "declaring conditions" for the actual iteration, one can declare a variable and then specify the conditions. Here one can't do it, and neither can do something like

if(5 > orderBean.getFiles().size() > 0)
like image 729
lisak Avatar asked Jan 10 '11 12:01

lisak


People also ask

How do you use greater than less than signs together?

When a number is bigger than or smaller than another number, greater than less than symbols are used. If the first number is greater than the second number, greater than symbol (>) is used. If the first number is less than the second number, less than symbol (<) is used.

How do you use greater than and less than in an if statement in Java?

Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true. Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true.

How do you remember greater than less than?

Another way to remember the greater than and less than signs is something that you may remember from grade school: the Alligator Method. Imagine the symbols as an alligator mouth with the numbers on each side being little fish. The alligator will always want to eat a larger number of fish.


1 Answers

Simple utility method:

public static boolean isBetween(int value, int min, int max)
{
  return((value > min) && (value < max));
}
like image 142
jtahlborn Avatar answered Oct 04 '22 00:10

jtahlborn