+ 10
What is the reason behind error in this code ?
int a=028; System.out.println(a);
9 Réponses
+ 11
when you add 0 to the beginning it is considered as octal digit (base 8)
so, it displayed value too large
Ref:
https://stackoverflow.com/questions/6935345/why-is-09-too-large-of-an-integer-number
+ 10
The presence of 0 as the very first digit of the number 028 makes JVM consider it as an Octal number with base 8. Since octal numbers can never contain a digit greater than 7, it gives an error. 028 is not fundamentally an octal number!
+ 7
thank you, for posting this question.
+ 5
it's because 8 doesn't exist in base8
+ 3
remove the zero
+ 2
thanks dev and sreejith these explanations are very helpful
+ 1
System.out.print(a);
0
whenever you start assigning integer from 0 then JVM assumes that it is as an Octal value. as you here defined here as integer but JVM will interpret as Octal so it will throw error.
0
You cant have the 0 at the beggining