Math Methods &
Random Range Practice

Read signatures, choose the right tool, store returned values, and generate random integers.

Task 1: Signature Check

Read the signatures, then test the matching calls

MethodPractice.java
java

Task 2: Choose the Tool

Write one line for each goal using the correct Math method

Goal 1
Absolute Value
-18

Print its absolute value with one correct Math call.

Goal 2
Larger Value
12, 29

Print the larger value from this pair.

Goal 3
Smaller Value
12, 29

Print the smaller value from the same pair.

Goal 4
Square
5

Print the square of this number using Math.

Task 3: Return Types

Store each returned value in a variable with the correct type

ReturnValuePractice.java
java

Task 4: Random Ranges

Turn Math.random() into random integers in the range you want

Target Range A
2 to 8

Create one variable that lands in this range.

int firstRange = ...
Target Range B
20 to 29

Create another variable that lands in this range.

int secondRange = ...
Final Step

Print both variables with System.out.println.

Bonus Challenge

Power Match

Generate two random integers, compare them, and use them to build one power expression.

  • 1. Generate one random integer from 2 to 8.
  • 2. Generate another random integer from 1 to 4.
  • 3. Use Math.max and Math.min to find the larger and smaller values.
  • 4. Use the larger value as the base and the smaller value as the exponent in Math.pow.
  • 5. Print the final power result.