This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt with octal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt with octal " Watch "doubt with octal " New topic
Author

doubt with octal

Gopala Krishnan
Greenhorn

Joined: Mar 04, 2001
Posts: 6
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

Joined: Feb 28, 2001
Posts: 67
hi there
there is no 8 in an octal number.
Jo Oehrlein
Greenhorn

Joined: Jan 03, 2001
Posts: 11
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: doubt with octal