01
Overview

Integer division and the modulo operator.

Two operators that split a number into quotient and remainder — the foundation of digit extraction, time conversion, and divisibility tests.

In Java, when both operands of / are integers, the result is the integer quotient — the decimal part is truncated. The % operator returns the remainder of that division.

Together they decompose a number: n = (n / k) * k + (n % k). This identity drives algorithms for digit extraction (last digit, count digits), time formatting, and place-value problems.

On the AP exam, these operators appear in MCQs about expression evaluation and in FRQs involving digit manipulation.

02
Core Concept

Truncating division; non-negative remainder for positives.

Both operands integers means integer result.

Basics

7 / 2  // 3   (truncated, not rounded)
7 % 2  // 1   (remainder)
10 / 3 // 3
10 % 3 // 1

For positive operands, % returns a value in [0, k).

Type matters

7 / 2      // 3   (int / int)
7.0 / 2    // 3.5 (double promotes the other operand)
(double) 7 / 2  // 3.5

If you need a decimal result, cast at least one operand to double.

Digit extraction

int n = 1234;
int lastDigit = n % 10;          // 4
int withoutLastDigit = n / 10;   // 123

Repeatedly applying both peels off digits right to left.

Time conversion

int totalSeconds = 3725;
int minutes = totalSeconds / 60;       // 62
int seconds = totalSeconds % 60;       // 5
int hours = minutes / 60;              // 1
int remainingMinutes = minutes % 60;   // 2
03
Key Vocabulary

Division and modulo vocabulary.

Used in every arithmetic FRQ.

Vocabulary
  • Integer division/ on two ints, truncates decimal.
  • Modulo%, remainder after division.
  • Truncation — discarding the fractional part.
  • Quotient — result of division.
  • Remainder — result of modulo.
  • Cast — converting types to control operation behavior.
04
AP Exam Focus

How / and % are tested.

Truncation, casting, and digit-extraction dominate.

Exam Focus
  • Truncation, not rounding. 7 / 2 is 3, never 4.
  • Cast for decimals. (double) sum / count avoids integer truncation.
  • Negative modulo. -7 % 3 is -1 — sign follows dividend.
  • Division by zero. n / 0 on ints throws ArithmeticException.
05
Worked Example

Sum the digits of a number.

Classic application of both operators.

Worked Example AP-style reasoning

Problem. Return the sum of the digits of n.

public int digitSum(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n = n / 10;
    }
    return sum;
}

Trace. For n = 1234:

  • 1234 % 10 = 4; sum = 4; n = 123.
  • 123 % 10 = 3; sum = 7; n = 12.
  • 12 % 10 = 2; sum = 9; n = 1.
  • 1 % 10 = 1; sum = 10; n = 0.
  • Loop exits.

Answer: 10.

06
Common Mistakes

Division and modulo pitfalls.

Mostly type and rounding mistakes.

Watch Out
  • Forgetting the cast. Integer division truncates without warning.
  • Assuming rounding. Java truncates toward zero, not rounds.
  • Negative modulo surprises. -7 % 3 is -1.
  • Division by zero on ints. Exception at runtime.
07
Reference Table

/ and % behavior.

Quick lookup.

Division Reference

AP Quick Reference
ExpressionResultNote
7 / 23Truncated.
7 % 21Remainder.
7.0 / 23.5Double division.
-7 % 3-1Sign follows dividend.
n / 0 (int)ExceptionArithmeticException.
08
Practice Tip

How to master / and %.

Drill digit-extraction; cast for decimals.

Practice Strategy
  • MCQ Practice — for each expression, identify the operand types first.
  • Java Lab — implement digitSum, countDigits, reverseNumber. Test negatives.
  • FRQ Practice — cast before dividing for percentages.
09
Section · 09

Practice — attempt these now.

AP-style assessments aligned to this lesson. Time them.

FRQ Practice 30 min 18 marks Pending

AP CSA Unit 09 Topic 03 Integer Division and Modulo FRQ Practice

AP-style topic practice assessment

Start