Week 13 · 13.3 · Wed, Oct 28 · We Do + Try Its
Divide and Remainder: Whole Numbers Only
This section shows the three kinds of steps on today's bench: dividing whole numbers, working a line in the right order, and following a box as its value changes.
The Whole Part and the Remainder
When a computer divides two whole numbers, it often keeps only the whole-number part of the answer and drops the rest. The part that is dropped can be worked out separately, and it is called the remainder. This section writes whole-number division as ÷ and the remainder as rem. It writes * for times, which is the symbol Java and the bench use for multiplication. In November, the class will see Java write all three as shown below.
1whole part: ÷ in this section, / in Java 2left over: rem in this section, % in Java 3times: * in this section, * in Java
How to find a ÷ b and a rem b:
- Find the largest number of whole times b fits into a. That number is a ÷ b.
- Multiply it by b, and subtract the product from a. What is left is a rem b.
- Check the work: b times the whole part, plus the remainder, gives back a.
Example 1. Find 17 ÷ 5 and 17 rem 5.
Show the solution
15 * 3 = 15 fits 25 * 4 = 20 too big, so 17 ÷ 5 is 3 317 - 15 = 2 so 17 rem 5 is 2 4check: 5 * 3 + 2 = 17
The answer is 3, not 3.4, because whole-number division keeps only the whole part.
Example 2. Find 4 ÷ 9 and 4 rem 9.
Show the solution
19 * 0 = 0 fits 29 * 1 = 9 too big, so 4 ÷ 9 is 0 34 - 0 = 4 so 4 rem 9 is 4 4check: 9 * 0 + 4 = 4
When a number is smaller than the divisor, the whole part is 0 and the remainder is the number itself.
Example 3. Find 36 ÷ 6 and 36 rem 6.
Show the solution
16 * 6 = 36 fits exactly, so 36 ÷ 6 is 6 236 - 36 = 0 so 36 rem 6 is 0
When a number divides evenly, the remainder is 0. The remainder is always smaller than the divisor, so n rem 6 can be 0, 1, 2, 3, 4 or 5, but never 6.
Work each one in your notebook first, then check it.
Try It 1. In whole-number division, what is 26 ÷ 8?
Try It 2. What is 26 rem 8?
Try It 3. What are 5 ÷ 12 and 5 rem 12?
Try It 4. Work 47 ÷ 6 the way Example 1 does. Give the whole part, the remainder and the check.
Check your answer
6 7 is 42, which fits, and 6 8 is 48, which is too big, so 47 ÷ 6 is 7. Then 47 - 42 is 5, so 47 rem 6 is 5. The check is 6 * 7 + 5 = 47.
One Step at a Time
A line with several operations is worked in a fixed order. First, work anything inside parentheses. Next, work *, ÷ and rem from left to right. After that, work + and - from left to right. Each step rewrites the whole line, so every new line shows one more operation finished.
Example 4. Work 20 - 14 ÷ 4.
Show the solution
120 - 14 ÷ 4 2= 20 - 3 ÷ comes before - 3= 17
Example 5. Work 7 + 8 ÷ 2 and (7 + 8) ÷ 2.
Show the solution
17 + 8 ÷ 2 (7 + 8) ÷ 2 2= 7 + 4 = 15 ÷ 2 parentheses first 3= 11 = 7
The two lines use the same numbers, but the parentheses change the order, and the order changes the answer.
Example 6. Work 7 ÷ 2 * 2.
Show the solution
17 ÷ 2 * 2 2= 3 * 2 ÷ and * go left to right 3= 6
The answer is 6, not 7, because 7 ÷ 2 drops the half before the times step.
Work each one in your notebook first, then check it.
Try It 5. Work this line one step at a time. What is its value?
130 - 12 ÷ 4
Try It 6. Work this line one step at a time. What is its value?
1(9 + 23) rem 4
Try It 7. Work this line one step at a time. What is its value?
19 ÷ 4 * 4
Boxes That Change
On the bench, a box holds one value, and an arrow puts a new value in it. A line that uses a box reads the value the box holds at that moment. A trace table records every box after each line runs.
Example 7. Find how many hours and minutes 135 minutes make.
1mins ← 135 2hours ← mins ÷ 60 3mins ← mins rem 60 4show hours 5show mins
Show the solution
line mins hours shown 1 135 2 135 2 3 15 2 4 15 2 2 5 15 2 15
Line 2 reads 135, because mins still holds 135 there. Line 3 replaces 135 with 15, so lines 4 and 5 show 2 and then 15.
Example 8. Find the last two digits of 472.
1n ← 472 2ones ← n rem 10 3n ← n ÷ 10 4tens ← n rem 10
Show the solution
line n ones tens 1 472 2 472 2 3 47 2 4 47 2 7
The remainder after dividing by 10 is the last digit, and ÷ 10 drops that digit. After line 3, n holds 47, so line 4 finds 7.
The bench catches three common mistakes, and each one changes the answer. The first is writing a decimal answer, such as 3.5 for 7 ÷ 2. The second is doing + or - before ÷ or rem. The third is using a box's old value after a line has replaced it.
Sources: Gosling et al., The Java Language Specification, Java SE 21 Edition (2023); Oracle, The Java Tutorials: Operators and Expressions, Statements, and Blocks; course repository, Bench Basics B08 job data (2026).
Work each one in your notebook first, then check it.
Try It 8. After line 3, what does secs hold?
1secs ← 200 2m ← secs ÷ 60 3secs ← secs rem 60
Try It 9. Trace these lines the way Example 8 does. What do n and ones hold after line 3?
1n ← 385 2ones ← n rem 10 3n ← n ÷ 10
Check your answer
Line 2 finds 385 rem 10, which is 5, so ones holds 5. Line 3 replaces n with 385 ÷ 10, which is 38. After line 3, n holds 38 and ones holds 5.