what is the meaning of the <= (less than or equal) operator for boolean operations?

StackOverflow https://stackoverflow.com/questions/19524121

  •  01-07-2022
  •  | 
  •  

문제

I saw a piece of java code like this:

int y = 100;
boolean x = y <= 0;
System.out.println(x);

<= is strange for me due to this using way, Could anyone explain the <= here, how can I use it?

도움이 되었습니까?

해결책

The assignment operator = is of lower precedence in Java than <=, so <= is performed first. The boolean result of y <= 0 is assigned to x. It could have more clearly written:

boolean x = (y <= 0);

But the effect is the same.

다른 팁

Read it as:

boolean x = (y <= 0);

This means that:

  • x will be true if y is equal to or less than zero.
  • x will be false if y is greater strictly than zero.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top