PrepGo

AP Computer Science A Flashcards: Math Class

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Review key ideas with interactive flashcards. This set includes 10 cards to help you master important concepts.

What is the range of values returned by the `Math.random()` method?
The `Math.random()` method returns a `double` value that is greater than or equal to 0.0 and less than 1.0.
Card 1 of 10

All Flashcards (10)

What is the range of values returned by the `Math.random()` method?
The `Math.random()` method returns a `double` value that is greater than or equal to 0.0 and less than 1.0.
List four common methods from the `Math` class that are part of the Java Quick Reference.
Four common `Math` class methods are `abs()`, `pow()`, `sqrt()`, and `random()`.
Why don't you need to import the `Math` class to use it?
The `Math` class is part of the `java.lang` package, and all classes in this package are available by default in every Java program without an explicit import statement.
Write a Java expression to generate a random integer between 1 and 6, inclusive (like a standard die roll).
The expression is `(int)(Math.random() * 6) + 1`.
What is the result of the expression `Math.abs(-15.5)`?
The expression results in the value 15.5, which is the absolute value of -15.5.
What type of methods does the `Math` class contain?
The `Math` class contains only class methods (also known as static methods), which are called directly on the class itself.
What is the `Math` class in Java?
The `Math` class is part of the `java.lang` package and contains class methods for performing common mathematical operations.
How can the value from `Math.random()` be used to generate a random number in a specific range?
The value from `Math.random()` can be manipulated using arithmetic operations to scale the result and casting to convert it into a random `int` or `double` in a defined range.
What value is produced by the expression `Math.sqrt(Math.pow(3, 2) + 16)`?
The expression evaluates to 5.0, as `Math.pow(3, 2)` is 9.0, 9.0 + 16 is 25.0, and the square root of 25.0 is 5.0.
What is the primary goal when developing code that uses built-in mathematical libraries?
The goal is to write expressions that correctly incorporate calls to library methods and to accurately determine the value that is produced as a result.