In a quiz I found one question where i need to calculate out of below program
public static void main(String[] args) {
short x = 0;
int b = 08;
x +=b;
System.out.println("" + b + x );
}
It gives compilation error on
int b = 08;
As it an octal value, So I tried some different values
int b = 07 // working fine (decimal of same is 7)
int b = 08 // (Decimal value 8) // Compilation error
int b = 09 // (Decimal value 9) // Compilation error
int b = 010 // (Decimal value 8) // No Compilation error
As 08 and 010 have same decimal number then why 08 gives compilation error.
Because in octal notation, 010
!= 08
. Actually, 08
doesn't exist in octal number system. All you can use are numbers 0-7
(starting with a 0
).
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