+ 2

What is the answer of this code and why?

int x = 01012; System.out.println("value of x is"+ x);

20th Jun 2020, 2:57 PM
Nisha Gupta
Nisha Gupta - avatar
3 ответов
+ 3
Integers that begin with 0 will result in an octal. 01012 is the octal (base 8) value for the decimal (base 10) 522
20th Jun 2020, 3:27 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
1 0 1 2 (1*8^3)+(0*8^2)+(1*8^1)+(2*8^0) (1*512)+(0*64) + (1*8) +(2*1) 512+0+8+2 522 Any value prefixed with 0 means it is in octal. So that value will deduce to 522.
20th Jun 2020, 3:32 PM
Avinesh
Avinesh - avatar
+ 1
Okk thanku so muchh...
23rd Jun 2020, 10:03 AM
Nisha Gupta
Nisha Gupta - avatar