I came across below snippet. It outputs to 4 3 2 1
I never came across <--
in Java.
Is <--
an operator that makes the value of var1 to var2?
public class Test { public static void main(String[] args) { int var1 = 5, var2 = 0; while (var2 <-- var1) { System.out.print(" " + var1); } } }
The Java right shift operator >> is used to move the value of the left operand to right by the number of bits specified by the right operand.
It is called a 'NOT' operator. It can be used to convert false to true or vice versa. By using this operator, the logical state of an operand is reversed. In simple words, it inverts the value of a boolean. Read Also: What does \n and \t mean in Java.
When you place 2L in code, that is a long literal, so the multiplications promote the other int s to long before multiplication, making your calculations correct by preventing overflow. The basic rules here to know here are: Java has operator precedence.
<--
is not a new Java operator (even though it may look like it), but there are 2 normal operators: <
and --
while (var2 <-- var1)
is the same as while(var2 < (--var1))
, which can be translated to plain english as:
var1
variable ( --var
is a prefix decrementation, ie. decrement the variable before condition validation)var2 < var1
<--
There is no such operator in java.
It is var2 < (--var1)
A relational + decrement operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With