In my example, assume x=10 so mathematically result of 10/7 would be 1.42 but in the method its being truncated to 1 without any casting. Why would it be so ?
You are using a "/" operator which would perform only integer division. The result of using this operator is only the integer part of the entire divison operation!! Hence the result is only 1 and not 1.42
Mel, thanks for your replies. I googled some more information on this and found that "/" can also perform floating point division provided atleast one of the operands is of type float.
Looks like "/" operator is overloaded.
I was thinking, it would depend on the result value and not on the operand types for determining the result type. And one would expect an error and not truncation unless the result is casted. I was wrong.
Thanks again for helping me clear this up. And I do have K&B and I love it !
i think the answer is simple x is an int x/7 is a division of two integer, so the result is an integer an int is implicitly convert to long
Trirange Portal Server 2007 is a Web 2.0, AJAX Portal Server with CMS, workflow, personalization, versioning management, collaboration features<br /><a href="http://www.trirange.com" target="_blank" rel="nofollow">http://www.trirange.com</a>
i think the answer is simple x is an int x/7 is a division of two integer, so the result is an integer an int is implicitly convert to long
I dont think its x/7 , I think therei s a type and it should read x/y otherwise whole question would not make sence,.... (and as number seven is right above letter 'Y' maybe it was unintentinal mistake )))