• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt with octal

 
Gopala Krishnan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the following code:
1. public class aclass
2. {
3. public static void main(String[] args)
4. {
5. int i = 015;
6. int j = 032;
7. int k = 078;
8. System.out.println(i);
9. System.out.println(j);
10. System.out.println(k);
11. }
12. }
when compiled tells that "aclass.java:7:Invalid character in octal number.
int k = 078;"
here the mark points to the prefix zero.
what is the mistake here.
Thanks in advance
 
lee dalais
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there
there is no 8 in an octal number.
 
Jo Oehrlein
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to expand on the previous answer, an octal number is in base 8. That means the valid digits are 0-7. Think about our "normal" base 10 numbers -- valid digits are 0-9. Binary is base 2 so valid digits are 0 and 1.
Hex is the same in that the valid digits have values 0-15, but to keep them to a single character 10 is replaced with A, 11 with B, 12 with C, 13 with D, 14 with E, and 15 with F.
The value 8 in octal is actually 10.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic