AP CSA Unit-Level MCQ
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.
Answered 0 of 15
Choose one answer.
Code Tracing 01 - Integer Division and Mod: track the final printed value.
int total = 18;
int bonus = 5;
int group = 3;
int result = (total + bonus) / group;
result = result * group + total % group;
System.out.print(result);All 15 integer division and mod questions
Work through the interactive quiz above first. This is the full integer division and mod question set with worked solutions, so students can review any question after attempting it.
1.Code Tracing 01 - Integer Division and Mod: track the final printed value.
int total = 18; int bonus = 5; int group = 3; int result = (total + bonus) / group; result = result * group + total % group; System.out.print(result);- 23
- 7
- 22
- 21
Show worked solution
Correct answer: 21
The first division uses integer division. The quotient is multiplied back by group, and the remainder from total is added.
2.Code Tracing 12 - Integer Division and Mod: follow the variable updates.
int views = 26; int added = 7; int pageSize = 5; int pages = views / pageSize; int leftover = (views + added) % pageSize; System.out.print(pages + leftover);- 8
- 6
- 1
- 13
Show worked solution
Correct answer: 8
Both / and % are integer operations here. The variables pages and leftover are computed separately before the final addition.
3.Code Tracing 28 - Integer Division and Mod: trace the branch and loop path.
int minutes = 38; int seconds = 10; int bucket = 3; int totalSeconds = minutes * 60 + seconds; System.out.print(totalSeconds / bucket);- 763
- 1
- 770
- 764
Show worked solution
Correct answer: 763
The multiplication and addition build totalSeconds first. Dividing two ints truncates any fractional part.
4.Code Tracing 39 - Integer Division and Mod: watch the index changes.
int x = 46; int y = 5; int group = 5; int cycle = 5; int value = (x + y) / group; System.out.print(value % cycle);- 2
- 0
- 1
- 10
Show worked solution
Correct answer: 0
The quotient is found first using integer division. The modulus is then applied to that quotient, not to the original sum.
5.Code Tracing 50 - Integer Division and Mod: evaluate the state change step by step.
int n = 54; int base = 3; int left = n / base; int right = n % base; System.out.print(left * 10 + right);- 179
- The code does not compile.
- 180
- 54
Show worked solution
Correct answer: 180
The quotient and remainder are computed separately. The quotient is scaled by 10 before the remainder is added.
6.What is printed by the following code segment?
int n = 3725; int sum = n / 1000 + n / 100 % 10 + n / 10 % 10 + n % 10; System.out.print(sum);- 15
- 17
- 3725
- 20
Show worked solution
Correct answer: 17
Each term isolates one digit of a four-digit number, and 3 + 7 + 2 + 5 is 17.
7.What is printed by the following code segment?
int total = 0; for (int i = 1; i <= 20; i++) { if (i % 3 == 0 && i % 5 != 0) { total += i; } } System.out.print(total);- 63
- 78
- 48
- 33
Show worked solution
Correct answer: 48
The multiples of 3 up to 20 are 3, 6, 9, 12, 15, and 18, and 15 is excluded because it is also a multiple of 5.
8.What is printed by the following code segment?
int mins = 545; int h = mins / 60; int rest = mins % 60; System.out.print(h + ":" + rest / 10 + rest % 10);- 9:5
- 9:50
- 8:65
- 9:05
Show worked solution
Correct answer: 9:05
The remainder is 5, so the tens digit is 0 and the ones digit is 5, printing a padded minute field.
9.What is printed by the following code segment?
int n = -14; int d = 4; System.out.print(n / d * d + n % d);- -14
- -16
- -12
- -10
Show worked solution
Correct answer: -14
Java guarantees that the quotient times the divisor plus the remainder returns the original value, even for negatives.
10.What is printed by the following code segment?
int count = 0; int n = 1; while (n <= 100) { if (n % 7 == 0 || n % 11 == 0) { count++; } n++; } System.out.print(count);- 23
- 22
- 14
- 9
Show worked solution
Correct answer: 22
There are 14 multiples of 7 and 9 of 11 up to 100, and 77 is counted once because || does not double count.
11.What is printed by the following code segment?
int n = 1024; int steps = 0; while (n % 2 == 0) { n /= 2; steps++; } System.out.print(n + " " + steps);- 2 9
- 1 11
- 1 10
- 0 10
Show worked solution
Correct answer: 1 10
Ten halvings reduce 1024 to 1, which is odd, so the loop stops there.
12.What is printed by the following code segment?
int a = 100; int b = 36; while (b != 0) { int t = a % b; a = b; b = t; } System.out.print(a);- 36
- 100
- 12
- 4
Show worked solution
Correct answer: 4
This is the Euclidean algorithm, and the greatest common divisor of 100 and 36 is 4.
13.What is printed by the following code segment?
int n = 6; int result = 1; while (n > 1) { result *= n % 4 == 0 ? 1 : n; n--; } System.out.print(result);- 180
- 720
- 30
- 120
Show worked solution
Correct answer: 180
The conditional operator replaces every multiple of 4 with 1, so 4 drops out and the product is 6 times 5 times 3 times 2, or 180.
14.What is printed by the following code segment?
int digits = 0; int n = 100000; while (n > 0) { digits++; n /= 10; } System.out.print(digits);- 5
- 6
- 7
- 100000
Show worked solution
Correct answer: 6
Each pass removes one digit, and 100000 has six of them before the value reaches 0.
15.What is printed by the following code segment?
int n = 255; String out = ""; while (n > 0) { out = n % 2 + out; n /= 2; } System.out.print(out);- 255
- 10000000
- 11111111
- 11111110
Show worked solution
Correct answer: 11111111
Repeated division by 2 with the remainder prepended builds the binary form, and 255 is eight ones.
