Why is 010 not equal to 10? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why is 010 not equal to 10?

A Java challenge question asked, "what is the output of the following code? System.out.println(010==10);" The correct answer was false, so my question is why does the leading zero make these values unequal?

10th May 2017, 4:55 AM
Kaleb Stott
Kaleb Stott - avatar
4 Answers
+ 12
010 is an octal value (8), while 10 is decimal.
10th May 2017, 5:56 AM
Karl T.
Karl T. - avatar
+ 1
so number starting with 0 is octal in java???...
7th Jan 2018, 7:33 AM
Rohit lovesMusic
Rohit lovesMusic - avatar
0
maybe that is string
10th May 2017, 5:56 AM
Agung Ramadhan Putra
Agung Ramadhan Putra - avatar
0
because java accepts it as an octal value, So 010 = 8. while 10 is you know.
3rd Sep 2017, 2:40 AM
Rocky