Computer Applications
What is wrong with the following statements? Explain.
i. result = (5/10) * Math.sqrt( a );
ii. result = math.sqrt(b * b - 4 * a * c) / ( 2 * a );
Java Math Lib Methods
18 Likes
Answer
i. result = (5/10) * Math.sqrt( a );
(5/10) will lead to integer division as both numerator and denominator are integers. So result of (5/10) will be 0 instead of 0.5 and the entire expression will always result in 0.
ii. result = math.sqrt(b * b - 4 * a * c) / ( 2 * a );
math should be written as Math. As Java is case-sensitive so it treats math and Math differently.
Answered By
9 Likes