Is there any difference affecting program efficiency between x <= 10
and x < 11
? Are there any other differences?
Thank you
Difference between x++ and x= x+1 in Java programmingx++ automatically handles the type casting where as x= x + 1 needs typecasting in case of x is not an int variable. See the example below.
In Java, parentheses() and Array subscript[] have the highest precedence in Java.
+ is an arithmetic operator while += is an assignment operator.. When += is used, the value on the RHS will be added to the variable on the LHS and the resultant value will be assigned as the new value of the LHS..
Hope this helped. it's simple, --x will be decremented first and then gets evaluated. whereas the x-- will be evaluated first and then gets decremented.
Refer http://en.wikipedia.org/wiki/Java_bytecode_instruction_listings
For example, for x <= 10
, if_icmple
instruction will be used and for x < 11
, if_icmplt
instruction will be used. Both should have same efficiency.
No difference for program, I think this is more personal taste.
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