wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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.
 
Consider Paul's rocket mass heater.
 
subject: doubt with octal
 
Similar Threads
Question from jqplus
Initialization
Integer data type
Array Indexing
Compiler Error The integer Number is too large:078