AP Computer Science A Practice Quiz: Math Class
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 10 questions to check your progress.
Question 1 of 10
All Questions (10)
A) 15.5
B) -15.5
C) 15
D) -15
Correct Answer: A
The `Math.abs()` method returns the absolute (non-negative) value of its argument. The absolute value of -15.5 is 15.5.
A) 12.0
B) 7.0
C) 64.0
D) 81.0
Correct Answer: D
The `Math.pow(base, exponent)` method calculates the value of the first argument raised to the power of the second argument. In this case, it calculates 3.0 to the power of 4.0, which is 3 * 3 * 3 * 3 = 81.0.
A) The `Math` class must be imported using `import java.util.Math;` before use.
B) An object of the `Math` class must be instantiated to call methods like `sqrt()`.
C) The `Math` class is part of the `java.lang` package and is available by default.
D) The `Math.random()` method is the only class method in the `Math` class.
Correct Answer: C
The provided content states, 'The Math class is part of the java.lang package. Classes in the java.lang package are available by default.' Therefore, no import is needed. The content also states it contains 'only class methods,' meaning no object is needed.
A) 4.0
B) 8.0
C) 16.0
D) 32.0
Correct Answer: B
The `Math.sqrt()` method returns the correctly rounded positive square root of a double value. The square root of 64.0 is 8.0.
A) (int) (Math.random() * 10)
B) (int) (Math.random() * 11)
C) (int) (Math.random() * 10) + 1
D) (int) (Math.random() + 10)
Correct Answer: C
`Math.random()` produces a double in the range [0.0, 1.0). Multiplying by 10 results in the range [0.0, 10.0). Casting to an `int` truncates the decimal, resulting in an integer from 0 to 9. Adding 1 shifts this range to 1 to 10, inclusive.
A) A `double` value greater than or equal to 0.0 and less than 1.0
B) A `double` value greater than 0.0 and less than or equal to 1.0
C) An `int` value, either 0 or 1
D) A `double` value greater than or equal to -1.0 and less than 1.0
Correct Answer: A
The `Math.random()` method returns a `double` value with a positive sign, greater than or equal to 0.0 and less than 1.0. This range is often represented as [0.0, 1.0).
A) 10 to 20, inclusive
B) 10 to 21, inclusive
C) 11 to 20, inclusive
D) 11 to 21, inclusive
Correct Answer: A
`Math.random()` is in the range [0.0, 1.0). `Math.random() * 11` is in the range [0.0, 11.0). Casting to `int` results in an integer from 0 to 10. Adding 10 to this range shifts it to 10 to 20, inclusive.
A) 12.0
B) 13.0
C) 17.0
D) 169.0
Correct Answer: B
The expression is evaluated from the inside out. `Math.pow(5.0, 2.0)` is 25.0. `Math.abs(-144.0)` is 144.0. The sum is 25.0 + 144.0 = 169.0. Finally, `Math.sqrt(169.0)` is 13.0.
A) By creating a new `Math` object and calling the method on that object.
B) By calling the method directly on the `Math` class itself, like `Math.pow()`.
C) By using them as arithmetic operators, like `x pow y`.
D) By importing them statically and calling them by method name only, like `pow()`.
Correct Answer: B
The content states that 'The Math class contains only class methods.' Class methods (also known as static methods) are called on the class name itself, not on an instance of the class. For example, `Math.pow(2, 3)`.
A) Math.random() + 50
B) (int) (Math.random() * 50)
C) Math.random() * 50
D) Math.random() * 49
Correct Answer: C
`Math.random()` produces a `double` in the range [0.0, 1.0). To scale this range up to [0.0, 50.0), you must multiply the result by 50. Option B produces an `int`, not a `double`. Option A produces a `double` in the range [50.0, 51.0). Option D produces a `double` in the range [0.0, 49.0).