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.
The modulo operator (%) gives you the remainder of a division, 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 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.
The modulo operator lives in Unit 1 (Primitive Types) 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.
Keep studying AP Computer Science A Unit 4
Division Symbol (/) (Unit 1)
Integer division 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 error.
Loops and Iteration (Unit 4)
Modulo is the classic loop 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.
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.
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.
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.
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.
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.
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.
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.
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.