int x = 100;
int y = 200;
boolean result = false;
result = x > y || y++ > 200;
System.out.println("x > y || y++ > 200 = " + result);
|| The operator says that if either of them is true, it displays true If it's y++, isn't the value 201? Then shouldn't it be marked as true?
java
I don't know much about Java, but... When I searched java++ operation on Google, this information came out.
The point is, ++a
increases the value and then returns it right away. a++
also increases the value (behind), but returns the value that has not yet changed. So it actually seems like it's going to work out later.
Then maybe you want:
int x = 100;
int y = 200;
boolean result = false;
result = (x > y || ++y > 200); // <-- Important here
System.out.println("x > y || ++y > 200 --> " + result); // --> true
© 2024 OneMinuteCode. All rights reserved.