---
title: "Modulo Operator (%) — AP Comp Sci A Definition & Uses"
description: "The modulo operator (%) returns the remainder after integer division in Java. Learn how AP CSA tests it with even/odd checks, digit extraction, and loops."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/modulo-operator-percent"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 4"
---

# Modulo Operator (%) — AP Comp Sci A Definition & Uses

## Definition

The modulo operator (%) in Java returns the remainder when one number is divided by another, so 7 % 3 evaluates to 1. In AP Computer Science A it's a core arithmetic operator alongside +, -, *, and /, and it shows up constantly in even/odd checks, digit extraction, and wrap-around logic.

## What It Is

The [modulo operator](/ap-comp-sci-a/key-terms/modulo-operator "fv-autolink") (%) gives you the **remainder** of a [division](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr "fv-autolink"), not the quotient. So `7 % 3` is `1`, because 3 goes into 7 twice with 1 left over. It works hand-in-hand with integer division: `7 / 3` tells you *how many times* the divisor fits (2), and `7 % 3` tells you *what's left* (1). Together they fully describe a division problem.

In Java, % works on both `int` and `double` values, has the **same precedence as * and /** (evaluated left to right), and the sign of the result matches the sign of the **left operand** (the dividend), so `-7 % 3` is `-1`. The three [patterns](/ap-comp-sci-a/unit-1/why-programming-why-java/study-guide/lVK6rmrBuug17i1Hna9z "fv-autolink") you'll use over and over: `n % 2 == 0` checks if a number is even, `n % 10` grabs the last digit of a number, and `n % k == 0` checks whether n is divisible by k. If a number is smaller than the divisor, modulo just returns the number itself (`3 % 5` is `3`), which trips a lot of people up.

## Why It Matters

The modulo operator lives in [Unit 1](/ap-comp-sci-a/unit-1 "fv-autolink") ([Primitive Types](/ap-comp-sci-a/key-terms/primitive-types "fv-autolink")) as one of Java's arithmetic operators, but it refuses to stay there. It's the engine behind some of the most common code patterns in the entire course. Checking evenness in a loop, peeling digits off an integer one at a time, cycling through positions in an array, alternating behavior every other iteration. All of those run on %. The exam loves it precisely because it tests whether you actually trace arithmetic the way Java does (with remainders and truncating integer division) instead of the way your calculator does. If you can confidently evaluate expressions mixing %, /, and * with correct precedence, you've locked down one of the most reliable point sources in Unit 1 and beyond.

## Connections

### Division Symbol (/) (Unit 1)

[Integer division](/ap-comp-sci-a/key-terms/integer-division "fv-autolink") and modulo are two halves of the same operation. With ints, `/` gives the quotient and throws away the remainder, while `%` gives you exactly the part that `/` threw away. AP questions frequently use both in the same expression to test whether you keep them straight.

### Variable Declaration & Initialization (Unit 1)

The result type of % depends on the operand types. `int % int` produces an `int`, so how a variable was declared determines what `%` hands back and what you can store the result in without a [compile](/ap-comp-sci-a/key-terms/compile "fv-autolink") error.

### Loops and Iteration (Unit 4)

Modulo is the classic [loop](/ap-comp-sci-a/key-terms/loop "fv-autolink") sidekick. `i % 2 == 0` makes a loop do something every other pass, and `n % 10` inside a while loop with `n / 10` extracts digits one at a time. Digit-processing loops are a staple free-response and multiple-choice pattern.

### Array Indexing (Unit 6)

Writing `index % arr.length` keeps an index inside array bounds no matter how big it grows. This wrap-around trick turns a straight line of indexes into a circle, which is how you cycle through an array repeatedly without an ArrayIndexOutOfBoundsException.

## On the AP Exam

Modulo shows up most often in multiple-choice expression evaluation. You'll see a stem like "What is the value of `17 % 5 + 17 / 5`?" and need to compute it exactly as Java would (answer: 2 + 3 = 5). Watch for three traps: forgetting that % and / share precedence with * and evaluate left to right, assuming integer division rounds instead of truncating, and forgetting that a negative dividend gives a negative result. On free-response questions, % rarely gets named directly, but writers expect you to reach for it yourself when a method needs to check divisibility, separate digits, or alternate behavior. Recognizing "this needs modulo" is the skill being graded.

## Modulo Operator (%) vs Division Symbol (/)

With two ints, `/` returns the quotient with everything after the decimal point chopped off (truncated, not rounded), while `%` returns the remainder. So `7 / 2` is `3` and `7 % 2` is `1`. Students mix these up constantly on MCQs, especially when both appear in one expression. A quick sanity check is that `(a / b) * b + (a % b)` always gets you back to `a`.

## Key Takeaways

- The modulo operator (%) returns the remainder of a division, so 7 % 3 evaluates to 1, not 2.33.
- % has the same precedence as * and /, and Java evaluates them left to right within an expression.
- n % 2 == 0 tests for even numbers, and n % k == 0 tests whether n is divisible by k.
- n % 10 gives the last digit of an integer, and pairing it with n / 10 in a loop processes a number digit by digit.
- When the dividend is smaller than the divisor, modulo returns the dividend unchanged, so 3 % 5 is 3.
- With a negative left operand the result is negative in Java, so -7 % 3 evaluates to -1.

## FAQs

### What does the modulo operator (%) do in Java?

It returns the remainder after dividing the left operand by the right one. For example, 17 % 5 evaluates to 2, because 5 fits into 17 three times with 2 left over.

### Does 7 % 2 give you 3.5?

No. Modulo never gives you the decimal result of division. 7 % 2 is 1 (the remainder), while 7 / 2 with ints is 3 (the truncated quotient). If you want 3.5, you need at least one operand to be a double and the / operator.

### What's the difference between % and / in Java?

With integers, / gives the quotient with the fractional part chopped off, and % gives the leftover remainder. So 13 / 4 is 3 and 13 % 4 is 1. They're complementary: (13 / 4) * 4 + (13 % 4) gets you back to 13.

### What is 3 % 5?

It's 3. When the dividend is smaller than the divisor, the divisor fits in zero times, so the entire dividend is the remainder. This is one of the most common modulo traps on AP CSA multiple-choice questions.

### How does modulo work with negative numbers in Java?

The result takes the sign of the left operand (the dividend). So -7 % 3 is -1, and 7 % -3 is 1. If a question mixes negatives with %, check the sign of the number on the left.

## Related Study Guides

- [4.12 Traversing 2D Arrays](/ap-comp-sci-a/unit-4/traversing-2d-arrays/study-guide/ZBcYqrg8FMJ49z1XpR8f)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/modulo-operator-percent#resource","name":"Modulo Operator (%) — AP Comp Sci A Definition & Uses","url":"https://fiveable.me/ap-comp-sci-a/key-terms/modulo-operator-percent","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/modulo-operator-percent#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T00:50:33.021Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/modulo-operator-percent#term","name":"Modulo Operator (%)","description":"The modulo operator (%) in Java returns the remainder when one number is divided by another, so 7 % 3 evaluates to 1. In AP Computer Science A it's a core arithmetic operator alongside +, -, *, and /, and it shows up constantly in even/odd checks, digit extraction, and wrap-around logic.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/modulo-operator-percent","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What does the modulo operator (%) do in Java?","acceptedAnswer":{"@type":"Answer","text":"It returns the remainder after dividing the left operand by the right one. For example, 17 % 5 evaluates to 2, because 5 fits into 17 three times with 2 left over."}},{"@type":"Question","name":"Does 7 % 2 give you 3.5?","acceptedAnswer":{"@type":"Answer","text":"No. Modulo never gives you the decimal result of division. 7 % 2 is 1 (the remainder), while 7 / 2 with ints is 3 (the truncated quotient). If you want 3.5, you need at least one operand to be a double and the / operator."}},{"@type":"Question","name":"What's the difference between % and / in Java?","acceptedAnswer":{"@type":"Answer","text":"With integers, / gives the quotient with the fractional part chopped off, and % gives the leftover remainder. So 13 / 4 is 3 and 13 % 4 is 1. They're complementary: (13 / 4) * 4 + (13 % 4) gets you back to 13."}},{"@type":"Question","name":"What is 3 % 5?","acceptedAnswer":{"@type":"Answer","text":"It's 3. When the dividend is smaller than the divisor, the divisor fits in zero times, so the entire dividend is the remainder. This is one of the most common modulo traps on AP CSA multiple-choice questions."}},{"@type":"Question","name":"How does modulo work with negative numbers in Java?","acceptedAnswer":{"@type":"Answer","text":"The result takes the sign of the left operand (the dividend). So -7 % 3 is -1, and 7 % -3 is 1. If a question mixes negatives with %, check the sign of the number on the left."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Unit 4","item":"https://fiveable.me/ap-comp-sci-a/unit-4"},{"@type":"ListItem","position":4,"name":"Modulo Operator (%)"}]}]}
```
