Skip to main content

Unit 1 · Using Objects and Methods

Integer Division and Mod

Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.

What integer division and mod covers

Integer division in Java discards the fractional part rather than rounding, and it truncates toward zero, so 7 / 2 is 3 and -7 / 2 is -3. The mod operator % returns the remainder of that division and takes the sign of the left operand, which means -7 % 2 is -1, not 1. Together these two operators power digit extraction, even and odd tests, wrapping values into a range, and index arithmetic.

Where students lose points

Negative operands are the classic trap. Students who memorize "mod is always positive" from math class get every negative case wrong. The second trap is digit extraction order: n % 10 gives the last digit and n / 10 removes it, and reversing those two is a very common slip inside a while loop.

How it shows up on the AP exam

Unit 1 arithmetic that keeps returning in Unit 2 loops. Digit-processing loops built on / 10 and % 10 are a recurring MCQ and FRQ pattern, so fluency here saves time on the whole exam.

For practice use only.

Integer Division and Mod MCQ Practice

AP CSA integer division and mod practice: truncation toward zero, negative operands, digit extraction, and the % patterns tested on the multiple-choice exam.

Question 1 of 15

Answered 0 of 15

Choose one answer.

Which option matches the complete output produced by this segment?

public class IntegerDivisionAndModContext
{
    public static void runExample()
    {
        int n = 5;
        for (int i = 3; i < 7; i++)
        {
            System.out.print(i % n);
        }
    }

    public static void main(String[] args)
    {
        runExample();
    }
}
Choose one answer.