Computer Applications

Given: double a = -8.35;
double p = Math.abs(Math.floor(a));
What will be the final value stored in the variable p?

  1. 9.0
  2. 8.0
  3. 7.0
  4. 8.5

Java Math Lib Methods

49 Likes

Answer

9.0

Reason — Math.floor() method returns the largest double value that is less than or equal to the argument and is equal to a mathematical integer. As -9.0 is the largest mathematical integer less than -8.35 so it is returned in this case. Math.abs() returns the absolute value of its argument so the final output is 9.0. The expression is solved as follows:

    p = Math.abs(Math.floor(a));
⇒ p = Math.abs(Math.floor(-8.35));
⇒ p = Math.abs(-9.0);
⇒ p = 9.0

Answered By

22 Likes


Related Questions