KnowledgeBoat Logo
|

Computer Applications

Given: double k = Math.rint(-9.4) + Math.sqrt(9.0);
What will be the final value stored in the variable k?

  1. -5.0
  2. -6.0
  3. -6.4
  4. -5.4

Java Math Lib Methods

31 Likes

Answer

-6.0

Reason — Math.rint(-9.4) will give -9.0 as it is nearest integer to -9.4. Math.sqrt(9.0) will give 3.0. So, the expression is solved as follows:

    k = Math.rint(-9.4) + Math.sqrt(9.0);
⇒ k = -9.0 + 3.0
⇒ k = -6.0

Answered By

14 Likes


Related Questions