Using the Math Class

AP Computer Science A· difficulty 2/5

double d = Math.abs(-3.5);
System.out.println(d);

What is printed?

  • A

    3.5

    check_circle
  • B

    -3.5

  • C

    3

  • D

    4

Explanation

Math.abs(double) returns the absolute value as a double, so -3.5 becomes 3.5.

Want 10 more like this — adaptive to your weak spots?

Related questions

AP Computer Science A · Using the Math Class Practice Question | Acemy