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
Mathclass is part of thejava.langpackage. Classes in thejava.langpackage are available by default.1.11.A.2 — The
Mathclass contains only class methods. The followingMathclass methods are part of the Java Quick Reference:static int abs(int x)— returns the absolute value of anintvalue.static double abs(double x)— returns the absolute value of adoublevalue.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 adoublevalue.static double random()— returns adoublevalue greater than or equal to0.0and less than1.0.
1.11.A.3 — The values returned from
Math.random()can be manipulated using arithmetic and casting operators to produce a randomintordoublein 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?