Sunday, November 9, 2008

Published 11/09/2008 by with 1 comment

integer number too large

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);
}
}
    email this       edit

1 comment:

  1. Please only use the capital 'L'.
    Consider
    long number=965478213241L;
    and
    long number=965478213241l;

    especially when using Courier New font

    ReplyDelete