0

I am trying to print this integer number

 int a=07;
System.out.println("Value of a is "+a);

it runs and shows value of a is 7 but when i change the value of a

 int a=08;
System.out.println("Value of a is "+a);

then it shows integer number too large

I dont know why... Can any body tell me ?

Engineer
  • 1,436
  • 3
  • 18
  • 33

2 Answers2

8

It's beause the JVM interprets this number as octal, and there's no symbol 8 in octal.

Any number starting by 0 is an octal number.

Oscar Pérez
  • 4,377
  • 1
  • 17
  • 36
0

08 is octal 8 which is not valid since octal numbers are only from 0 to 7.

You should try:

int a=8;
System.out.println("Value of a is "+a);
Adam Arold
  • 29,285
  • 22
  • 112
  • 207