Please enable JavaScript to use CodeHS

Chapter 2

Using Objects

2.9 Using the Math Class

Basic Math Operations

Using the Math Class

Random Numbers

Generating Random Numbers

Static Methods: Rectangle

Check Your Understanding

  1. Incorrect Correct No Answer was selected Invalid Answer

Exercise: Circle Area

Vocabulary

Term Definition
Static Methods Static methods are the methods in Java that can be called without creating an object of class. Static methods are called using the dot operator along with the class name unless they are defined in the enclosing class.
Math Class The Math class is part of the java.lang package and contains only static methods.
int abs(int x) Returns the absolute value of an int value
double abs(double x) Returns the absolute value of a double value
double pow(double base, double exponent) Returns the value of the first parameter raised to the power of the second parameter
double sqrt(double x) Returns the positive square root of a double value
double random() Returns a double value greater than or equal to 0.0 and less than 1.0
Math.random Can be manipulated to produce a random int or double in a defined range.