aspose file tools*
The moose likes Beginning Java and the fly likes 'long' with more than 10 digits won't compile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " Watch " New topic
Author

'long' with more than 10 digits won't compile

Nick Stevens
Greenhorn

Joined: Nov 13, 2004
Posts: 15
I'm working on an anagram solver and I've found that

int 1234567890;

compiles okay (as does long 1234567890);

long 12345678901;

generates the error ': integer number too large 12345678901'. I thought 'long' variables could consist of more digits than 'int' variables? Any suggestions would be much appreciated!
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3529
    
  15
Put an 'L' on the end to indicate it is a long

long l = 12345678901L;


Joanne
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
When you write

The compiler handles the number as an int and therefore this gives a compiler error. (All literals like that are considered int's by default)

To make the compiler handle this as a long, you have to append a 'l' or a 'L' to the number.

Now the compiler will know you really meant a long and not complain.
Nick Stevens
Greenhorn

Joined: Nov 13, 2004
Posts: 15
Thanks both of you for your help, I've added an l and it compiles okay - hurray! I wonder why the compiler assumes a long 'literal' is an int? I'll be unscrambling anagrams again now :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 'long' with more than 10 digits won't compile