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?

1
  • 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? Commented May 8, 2014 at 7:08

5 Answers 5

8

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

Sign up to request clarification or add additional context in comments.

Comments

2

If you write '0' as leading it indicate Octal

Comments

1

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

Comments

1

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

Comments

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);

  }

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.