Unit 1 Day 9: Integer Division & Modulo Practice

Unit 1, Section 1.9
Day 9 Practice • January 15, 2026
🎯 Focus: Integer Division & Modulo

Practice Question

Consider the following code segment:
int a = 17;
int b = 5;
int result = a / b + a % b;
System.out.println(result);
What is printed as a result of executing this code segment?
What This Tests: This question tests integer division (/) and the modulo operator (%). Both are frequently tested on the AP exam and are essential for understanding how Java handles integer arithmetic.

Key Concept: Integer Division vs Modulo

17 / 5  = 3   // Integer division: truncates decimal (not rounds!)
17 % 5  = 2   // Modulo: returns the remainder

// Think of it as: 17 = 5 × 3 + 2
//                     ↑     ↑
//                   (/)   (%)

Step-by-Step Trace

Expression Calculation Result
a / b 17 / 5 3 (truncated)
a % b 17 % 5 2 (remainder)
result 3 + 2 5

Common Mistakes

Mistake: Answer C (5.4)

Integer division does NOT produce decimals. When dividing two ints, the result is always an int. 17/5 = 3, not 3.4.

Mistake: Answer A (3)

This only accounts for a / b and forgets to add a % b.

Modulo Patterns

💡 Common Uses of Modulo

Check if even: n % 2 == 0

Check if odd: n % 2 == 1

Get last digit: n % 10

Wrap around: index % array.length

Related Topics

  • Section 1.3: Arithmetic Operators
  • Section 1.5: Type Casting
  • Section 2.9: Using % in loops
Difficulty: Medium • Time: 1-2 minutes • AP Skill: 2.B - Determine output

Want More Practice?

Master AP CSA with guided practice and expert help

Schedule 1-on-1 Tutoring Practice FRQs
Back to blog

Leave a comment

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