I successfully managed to solve a math problem using Java code. However, in doing so, I've also stumbled upon something weird.
In one of my calculations, I had to add 4 numbers: 13, 132, 320, and 201. I declared an int variable sum, and initialized it to 13 + 132 + 320 + 201.
int sum = 13 + 132 + 320 + 201;
When I printed the variable sum out, it returned a value of 666. Which makes sense, since adding those numbers on a calculator returns that value. However, I decided to then set the variable sum equal to something a little different. I decided to set sum equal to 013 + 132 + 320 + 201.
sum = 013 + 132 + 320 + 201;
However, when I printed this value out, I got 664. I decided to add one more zero to the left of 013.
sum = 0013 + 132 + 320 + 201;
And sum returned the same value, 664.
So basically, whenever I add the numbers just like that without any unnecessary zeroes, sum returns the correct value. But when I add those unecessary zeroes, sum returns a slightly different answer. Is there a reason as to why putting zeroes before a number causes a slightly different result?