0

I have declared a variable int i = 08; I got an error in netbeans that "integer number too large"! Can anyone explain why this happens. I am coding in Java.

for (int i = 08; l <= Integer.parseInt(dd); i++)

To remove the error I then tried int i = 8 which works; Now I do not understand that why int i = 08 do not work?

Blue Ocean
  • 282
  • 1
  • 10
  • Googling for "java integer number too large 08" gives many results from which the answer could easily have been derived. Additionally, there are some duplicate questions on SO. So, why got this question upvoted? – Seelenvirtuose May 08 '14 at 07:08

5 Answers5

8

Literal integer types starting at 0 are interpreted as octal base. Octal base doesn't allow 8, only digits from 0 to 7.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
2

If you write '0' as leading it indicate Octal

Sanjay Rabari
  • 2,091
  • 1
  • 17
  • 32
1

Leading 0 suggests 8-based number system, so viable digits there are 0 - 7

endriu_l
  • 1,649
  • 16
  • 20
1

The prefix "0" indicates "octal", and 8 is larger than the maximum-sized octal digit.

Michael Aaron Safyan
  • 93,612
  • 16
  • 138
  • 200
0

The prefix 0 indicates octal(8 base)(digits 0-7).

public class MainClass{

  public static void main(String[] argv){

    int intValue = 034;  // 28 in decimal
    int six = 06; // Equal to decimal 6
    int seven = 07; // Equal to decimal 7
    int eight = 010; // Equal to decimal 8
    int nine = 011; // Equal to decimal 9

    System.out.println("Octal 010 = " + eight);

  }

}
Owen Cao
  • 7,955
  • 2
  • 27
  • 35