This week's book giveaways are in the Jython/Python and Object-Oriented programming forums. We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line! See this thread and this one for details.
Hi guys, I'm a bit confused about this question that appears on Marcus Greene's mock exam: Question 47) What will be output by the following line of code? System.out.println(010|4); 1) 14 2) 0 3) 6 4) 12 The answer given is 12, because "the octal notaction which means that the leading letter zero (not the letter O)) means that the first 1 indicates the number contains one eight and nothing else". I understand how you arrive at 12 from this conclusion, but I can't get how you're supposed to know that 010 is octal 8 and not binary 2 or something.. am i just incredibly dumb? can someone explain this please? Thanks guys! P.S. apologies if this question has already been answered somewhere else on this board but I couldnt find anything from searching - thanks!
In java any numeric literal starting with a 0 is considered as octal and nothing else. So it is considered as octal and 010 octal is 8 decimal. I also have seen traps in some questions which will give a literal as 0739. In this case literal 0739 is wrong since you cannot have digit with more than 7 in octal. Hope this helps -- Hari Gangadharan
<B>Hari Gangadharan</B><BR>Unix is user friendly..<BR>but it chooses to whom it is friendly with!
posted 18 years ago
Thanks Hari! I understand this now! thanks for taking the time to answer :-)
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...