"Integer Number Too Large" Error Message for 600851475143

Integer number too large

You need to use 4545454545l or 4545454545L to qualify it as long. Be default , 4545454545 is an int literal and 4545454545 is out of range of int.

It is recommended to use uppercase alphabet L to avoid confusion , as l and 1 looks pretty similar

You can do :

if(Long.valueOf(4545454545l).equals(Long.parseLong(morse)) ){
System.out.println("2");
}

OR

if(Long.parseLong(morse) == 4545454545l){
System.out.println("2");
}

As per JLS 3.10.1:

An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int (§4.2.1).

Integer number too large in Long type variable

08 and 00008 are parsed as octal numbers, in which 8 and 9 are invalid digits. Remove the leading zeroes.

integer number too large in arraylist

Here the problem is that in java double literals end with a d if you didn't put d it will consider as an integer, hence integer no too large error will throw.

In this case you are missing d, so add d for the numbers which dont have a precision..

eg double no = 1555760766d;

Java long number too large error?

All literal numbers in java are by default ints, which has range -2147483648 to 2147483647 inclusive.

Your literals are outside this range, so to make this compile you need to indicate they're long literals (ie suffix with L):

long min = -9223372036854775808L;
long max = 9223372036854775807L;

Note that java supports both uppercase L and lowercase l, but I recommend not using lowercase l because it looks like a 1:

long min = -9223372036854775808l; // confusing: looks like the last digit is a 1
long max = 9223372036854775807l; // confusing: looks like the last digit is a 1

Java Language Specification for the same

An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int (§4.2.1).

Java Integer number too large in Date adding calculation

Add the token L after your numbers to turn them into long literals:

public void setDateExpired(String ticketType) {
if (ticketType.equals("Gold")) {
dateExpired = dateExpired + 2628000000L;
} else if (ticketType.equals("Silver")) {
dateExpired = dateExpired + 1209600000L;
} else {
dateExpired = dateExpired + 604800000L;
}
}

Without they L, the compiler interprets them as int literals, but the values are too big for the int type. The largest int value you can use is 2147483647 (though it's best not to mix types in cases like this, and just use longs throughout).

You'll also run into the issue of adding incorrect types. Either change dateExpired to be a long (and convert it to a Date later), or use this form:

dateExpired = new Date(dateExpired.getTime() + 604800000L) 

Just an aside, it might help you later to document what the big numbers mean:

dateExpired = dateExpired + 86400000L; // one day


Related Topics



Leave a reply



Submit