Max Java literal number in eclipse

I have a line that looks like

if(numb2 < 10000000000000 & numb2 > 100000000000){

So, in Eclipse it says that 10000000000000 and 100000000000 are both from the integer literal range. Specifically

A literal of 1,000,000,000,000 of type int is out of range and a literal 1,000,000,000,000,000 of type int is out of range.

I changed the line so that it looked like

if(numb2 < 1000000000*10000 & numb2 > 100000000*1000){

but if you dialed a number in that range, he just said

Exception in thread "main" java.lang.NumberFormatException: For input string: "5555555555555"
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at twothousandthirteen.LuckyNumber.main(LuckyNumber.java:12)

I would like to know if there is a way to expand the literal range of numbers or do something to fix the problem.

Thanks KMehta p>

+5
source share
5 answers

int, 2 31 -1 2147483647, Integer.MAX_VALUE.

, 1000000000*10000, , , int, , java , .

, long (64 ) , L , ( java int), Long.parseLong(), .

, , int, long : 2 63 -1 9223372036854775807, Long.MAX_VALUE.

BigInteger.

+4

long:

if(numb2 < 10000000000000L && numb2 > 100000000000L){

... Long.parseLong int, -2,147,483,648 2,147,483,647.

Long.parseLong(input)

, int, , numb2 int, .

, boolean , &, &&. & - , , , ; && "".

0

numb2? int? , - int ~ 2 000 000 000. .

long, , long. :

if(numb2 < 10000000000000L & numb2 > 100000000000L){ 
0

If you want to use numbers from the int range, you will have to use a different type. Integer values ​​in eclipse go only up to 2 ^ 31-1 (signed). If you want to use a larger value, longs can reach 2 ^ 63-1.

If you need an even larger number, the double can become very large, but with very poor accuracy, so you should not use it if you need precision. Another way for huge values ​​is to use a class BigInteger, but this will create objects that can be difficult to handle.

0
source

All Articles