• Post Reply Bookmark Topic Watch Topic
  • New Topic

Octal Literal Max Number

 
Charissa Thomas
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am ready the OCA 7 certification study book and read that you can have up to 21 digits in an octal number, not including the leading zero but when I tried to compile this line:



I got the following error:

Octal.java:8: error: integer number too large: 0111111111111

Please advise how I would write a 21 digit octal number or if this is incorrect, I will need to report that for the books errata notes.  Thanks for anyone's guidance!
 
Ron McLeod
Saloon Keeper
Posts: 1289
149
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't suffix the value with a L or l (lower case ell) character, it is understood to be and integer, not a long, and you will be limited to the maximum value of an int.
 
Charissa Thomas
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Completely forgot about that.  Thanks a bunch for your quick response!
 
Roel De Nijs
Sheriff
Posts: 10763
148
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Charissa Thomas,

First of all, a warm welcome to CodeRanch!

Charissa Thomas wrote:Please advise how I would write a 21 digit octal number or if this is incorrect, I will need to report that for the books errata notes.

It is definitely not an errata item. Each integer literal in Java is by default an int. If you have a literal which is outside the range of an int, you need an indicator to tell the compiler it should be handled as a long and not an int; otherwise you'll end up with a compiler error (as you have experienced). Adding the L (or l) suffix will fix this compiler error. You'll find more detailed info in this post.

And here you'll find another topic about literals with a bunch of code snippets. And if you like to know what happens if you use suffix D (or d) and F (or f) in hexadecimal literals, you should definitely read this topic and this one.

Hope it helps!
Kind regards,
Roel
 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!