Skip to content
We know that the maximum value of an int is 2147483647. If we write any whole number more than 2147483647 in our Java program, we may get this error message 'integer number too large' but may be you are trying to store this large number in a long type variable, then what to do? The solution is to put the letter 'l' or 'L' after the number. This happens, because the compiler considers the whole number as int by default and we specify the large number by character 'l' or 'L' as long number. Now the compiler will consider the number as long.
For example, we are trying to compile the following Java code:
public class IntegerNumberTooLarge
{
public static void main(String args[])
{
long number=965478213245;
System.out.println(number);
}
}
We will get 'integer number too large' from the above program. Now write the program as below the problem will be solved.
public class IntegerNumberTooLargeSolution
{
public static void main(String args[])
{
long number=965478213245L;
System.out.println(number);
}
}
Please only use the capital 'L'.
ReplyDeleteConsider
long number=965478213241L;
and
long number=965478213241l;
especially when using Courier New font