I am developing an application in Android using Eclipse. I wrote the following code and in tests the first and third "if" block is not reachable. Why?
When I add a leading zero to a number, the equal operator returns false.
int var = 123; if (var == 0123) { //not reachable } if (var == 123) { //reachable } if (var == (int)0123) { //not reachable } if (var == (int)123) { //reachable }
It's the Addition assignment operator. Let's understand the += operator in Java and learn to use it for our day to day programming. x += y in Java is the same as x = x + y. It is a compound assignment operator. Most commonly used for incrementing the value of a variable since x++ only increments the value by one.
Short values are stored in 2 bytes and contains positive or negative integer numbers.
9 / 2 is integer division. It evaluates to 4.
0123
is an octal number (leading 0), while 123
is a decimal number.
so 0123 actually equals to 83.
Any integer Number Leading With Zero is octal Number (base 8).
0123
is octal Number and 123
is Decimal Number
0123 = (3*8^0) +(2*8^1)+(1*8^2)+(0*8^4) =3+16+64+0 =83
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