1.11 Math Class

Suggested Skills: 2.C, 4.A

LO 1.11.A — Develop code to write expressions that incorporate calls to built-in mathematical libraries and determine the value that is produced as a result.

  • 1.11.A.1 — The Math class is part of the java.lang package. Classes in the java.lang package are available by default.

  • 1.11.A.2 — The Math class contains only class methods. The following Math class methods are part of the Java Quick Reference:

    • static int abs(int x) — returns the absolute value of an int value.

    • static double abs(double x) — returns the absolute value of a double value.

    • static double pow(double base, double exponent) — returns the value of the first parameter raised to the power of the second parameter.

    • static double sqrt(double x) — returns the nonnegative square root of a double value.

    • static double random() — returns a double value greater than or equal to 0.0 and less than 1.0.

  • 1.11.A.3 — The values returned from Math.random() can be manipulated using arithmetic and casting operators to produce a random int or double in a defined range based on specified criteria. Each endpoint of the range can be inclusive (value is included) or exclusive (value is not included).

Last updated

Was this helpful?