+ 4
public class Main { public static void main(String[] args) { int i = 012345; System.out.println(i); } }
Why i am getting output result 5349
6 odpowiedzi
+ 19
Java recognize number starting with 0 as octal numbers, so converting 012345 to decimal will give 5347, see below the conversion:
(0 * 8^5)+(1*8^4)+(2*8^3)+(3*8^2)+(4*8^1)+(5*8^0)
=5349
//note: try not to use 0 in beginning of number for showing specific number of digits as it will be taken as octal by many languages(you can use other way if you want to put 0 in beginning, see link to post for that), also you can only use digits 0-7 in octal else it will give error.
https://www.sololearn.com/Discuss/1724342/?ref=app
+ 10
0 at the start, mean the number is in octal (base-8) not decimal (base-10)
+ 10
You just remove 0 & the program will be excute.
+ 5
I hope this is not question from challenges, way too much to calculate in such a short time 😐
+ 3
Remove the 0 and try again.
+ 1
Cause java know every integer which starts by 0 as a octal number not a decimal & (12345)8 to decimal is 5349