Literal integer types starting at 0
are interpreted as octal base. Octal base doesn't allow 8
, only digits from 0
to 7
.
Difference between 08 and 8 in for int variable in java [duplicate]
Вопрос
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?
Решение
Другие советы
If you write '0'
as leading it indicate Octal
Leading 0
suggests 8-based number system, so viable digits there are 0 - 7
The prefix "0" indicates "octal", and 8 is larger than the maximum-sized octal digit.
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);
}
}
Не связан с StackOverflow