• Post Reply Bookmark Topic Watch Topic
  • New Topic

int initialization  RSS feed

 
Rabin Poon
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int i=07;
int j=021;
int k=031;
System.out.println(i);
System.out.println(j);
System.out.println(k);
the above code gives output
7
17
25
But when i put
int i=08; or
int i=09; compilation error is given out. What is the logic behind iinitializing an int or a byte. WHy is the number 8 or 9 not allowed if the first digit is 0.
Thanks in advance.
[ January 02, 2004: Message edited by: Rabin Poon ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the first digit of an integral constant is 0, then it's an octal (base 8) constant. Valid octal digits are 0...7. 8 and 9 are not valid octal digits, as the error message should indicate.
For base 10 (normal decimal constants) don't use a leading 0.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!