Why this statement gives error ? Any explanation please?(The error is : integer number too large) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why this statement gives error ? Any explanation please?(The error is : integer number too large)

Int x = 081;

4th Feb 2020, 11:42 AM
Hichem GOUIA
Hichem GOUIA - avatar
4 Answers
+ 3
Java treats integers leading with 0 as octal numbers Best explanation I got from stackoverflow: Octal (base-8 number) 0123 means octal 123, that is 1*8*8 + 2*8 + 3, which equals 83. For some reason, octal floats are not available. Creating 0123 means the integer 83. Creating 0123F means the floating 123. When converted back to integer, it remains 123. "Just don't use the leading 0 if you don't mean octal. After all, they are not exactly useful(and programmers who do know about octal numbers will get confused when they see 09F)" Source: https://stackoverflow.com/questions/565634/integer-with-leading-zeroes
4th Feb 2020, 11:45 AM
HNNX 🐿
HNNX 🐿 - avatar
+ 3
if the number start with 0, it'll be registered as octal. but octal dont have 8 in its numbering system, only 0 to 7.
4th Feb 2020, 11:45 AM
Taste
Taste - avatar
+ 2
This is octal literal https://www.tutorialspoint.com/define-integer-literals-as-octal-values-in-java But max number in this system is 7, so "8" is cause
4th Feb 2020, 11:45 AM
Stephan
Stephan - avatar
+ 1
Try this. int x = 81; Why are you using 0 in front of 81?
4th Feb 2020, 11:46 AM
Maninder $ingh
Maninder $ingh - avatar