Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is better to use in Java? x <= 10 or x < 11?

Is there any difference affecting program efficiency between x <= 10 and x < 11 ? Are there any other differences?

Thank you

like image 249
user2290659 Avatar asked Apr 17 '13 12:04

user2290659


People also ask

Which is better x ++ or x x 1?

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.

Which of these has highest precedence Java?

In Java, parentheses() and Array subscript[] have the highest precedence in Java.

What is the difference between += and =+?

+ 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..

What is the difference between -- x and x --?

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.


2 Answers

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.

like image 90
Niraj Nawanit Avatar answered Sep 30 '22 10:09

Niraj Nawanit


No difference for program, I think this is more personal taste.

like image 32
Micha Avatar answered Sep 30 '22 10:09

Micha