integer number too large: Java

Java compiler will throw an error saying "integer number too large:"  when you compile the following code



public class Test
{
         public static void main(String a[])
         {
                 int i = 012;
                 int j = 078;    // compiler will complain at this line
                 System.out.println(i);
                 System.out.println(j);
          }
}

Reason behind this is that
A '0' (zero) in front of a number denotes octal number system like 012, 045 ,0xx anything
and octal number system uses digits 0 t0 7, so 8 is out of the range.
same happens with 019 or 048 or anything that is out of octal range.
this is the reason why compiler complains.


0 nhận xét:

Đăng nhận xét