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,705
  • 17
  • 73
  • 101
  • 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
  • 321,522
  • 82
  • 660
  • 783
7

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

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
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
  • 41,389
  • 58
  • 210
  • 364