3

Can I pass number greater than 999 999 999 as parameter in java.

When I do like this it gives compiler error the literal 999 999 999 9 of type is out of range

 passNumber(9999999999);

 public String passNumber(long number){
     if(number > 999999999)
         throw new BigNumberException("Number too large")
 }
Harry
  • 4,555
  • 16
  • 71
  • 100
  • See [this](http://stackoverflow.com/questions/8924896/java-long-number-too-large-error) and [this](http://stackoverflow.com/questions/769963/javas-l-number-long-specification-question) questions. – Lion Jul 15 '12 at 09:27

3 Answers3

9

It's because 9,999,999,999 is considered as an int by the compiler and is larger than Integer.MAX_VALUE (2,147,483,647).

You can use a long: 9999999999L.

assylias
  • 310,138
  • 72
  • 642
  • 762
7

Use 9999999999L to tell the compiler it's a long literal, and not an int literal.

JB Nizet
  • 657,433
  • 87
  • 1,179
  • 1,226
4

That's because 9 billion is out of integer range (signed int up to 2,147,483,647 and unsigned int up to 4,294,967,295).

Take a look here to learn more.

Steven Lu
  • 39,229
  • 55
  • 195
  • 348