AP CSA Unit 1.7: Math Class Methods Practice

Unit 1, Section 1.7
Day 7 Practice • January 13, 2026
🎯 Focus: Math Class Methods

Practice Question

Consider the following code segment:
int a = -7;
int b = 3;
int result = Math.abs(a) + Math.min(a, b);
System.out.println(result);
What is printed as a result of executing this code segment?

What This Tests: Section 1.7 covers the Math class. This question tests Math.abs() (absolute value) and Math.min() (minimum of two values). These static methods are essential tools on the AP exam.

Key Concept: Math Class Methods

Math.abs(-7)      → 7    // Absolute value (removes negative)
Math.abs(7)       → 7    // Already positive
Math.min(-7, 3)  → -7   // Returns smaller value
Math.max(-7, 3)  → 3    // Returns larger value
Math.pow(2, 3)   → 8.0  // 2³ = 8 (returns double)
Math.sqrt(16)    → 4.0  // Square root (returns double)

Step-by-Step Trace

Expression Calculation Result
Math.abs(a) Math.abs(-7) 7
Math.min(a, b) Math.min(-7, 3) -7
result 7 + (-7) 0

Output: 0

Common Mistakes

Mistake: Answer C (10)

This comes from thinking Math.min returns the absolute minimum (7 + 3 = 10). But Math.min(-7, 3) returns -7 because -7 < 3. The minimum is the smallest value, including negatives!

Mistake: Answer B (4)

This might come from |−7| − 3 = 7 − 3 = 4. But we're adding Math.min, not subtracting b.

Math Class Reference

AP Exam Math Methods

Math.abs(x) - Returns |x| (absolute value)

Math.pow(base, exp) - Returns base^exp (as double)

Math.sqrt(x) - Returns √x (as double)

Math.min(a, b) - Returns smaller of a and b

Math.max(a, b) - Returns larger of a and b

Math.random() - Returns random double [0.0, 1.0)

Related Topics

  • Section 1.3: Expressions
  • Section 3.7: Static Methods (Math methods are static)
  • Section 2.9: Using Math.random() for random integers
Difficulty: Medium • Time: 2-3 minutes • AP Skill: 2.C - Call methods

Completed Unit 1 Week 1! 🎉

Great job finishing all 7 days! Ready for more practice?

Premium Question Bank - Coming Soon! Schedule 1-on-1 Tutoring

300+ Unit 1 questions • Expert tutoring • 5.0 rating

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.