3.1 Lesson Outcomes
After completing this lesson, learners will be able to:
- Define the modulus operator.
- Perform remainder calculations.
- Determine odd and even numbers.
- Apply modulus operations in Java programs.
- Use modulus logic in practical applications.
3.2 Overview
The modulus operator is used in Java to calculate the remainder after division. The modulus operator is represented using the percentage symbol:
%
The modulus operator is important in:
- mathematical calculations,
- validation systems,
- gaming applications,
- counters,
- and decision-making logic.
This lesson introduces learners to practical uses of the modulus operator in Java programming.
Understanding the modulus operator is important because remainder calculations are commonly used in software applications.
PA1801 — Use the Modulus Operator
The modulus operator returns the remainder after division.
Java Example:
int result = 10 % 3;
System.out.println(result);
Expected Output
1
Practical Activity
Learners must:
- apply modulus operations,
- calculate remainders,
- and display outputs.
PA1802 — Determine Even Numbers
Even numbers have no remainder when divided by 2.
Java Example:
int number = 8;
if (number % 2 == 0) {
System.out.println(“Even Number”);
}
Practical Activity
Learners must:
- identify even numbers,
- apply modulus conditions,
- and display results.
PA1803 — Determine Odd Numbers
Odd numbers produce a remainder when divided by 2.
Java Example:
int number = 7;
if (number % 2 != 0) {
System.out.println(“Odd Number”);
}
Practical Activity
Learners must:
- identify odd numbers,
- apply conditional statements,
- and display outputs.
PA1804 — Check Divisibility
The modulus operator checks divisibility.
Java Example:
int number = 15;
if (number % 5 == 0) {
System.out.println(“Divisible by 5”);
}
Practical Activity
Learners must:
- test divisibility,
- apply modulus logic,
- and display results.
PA1805 — Create Counters Using Modulus
The modulus operator can control counters and repeating patterns.
Java Example:
for (int i = 1; i <= 10; i++) {
if (i % 3 == 0) {
System.out.println(i);
}
}
Practical Activity
Learners must:
- create counters,
- display repeating patterns,
- and apply modulus operations.
PA1806 — Create Multiplication Pattern Program
Modulus operations support pattern generation.
Java Example:
for (int i = 1; i <= 20; i++) {
if (i % 4 == 0) {
System.out.println(i);
}
}
Practical Activity
Learners must:
- generate patterns,
- identify multiples,
- and display results.
PA1807 — Create Complete Modulus Program
The modulus operator is used in practical Java applications.
Java Example:
public class ModulusExample {
public static void main(String[] args) {
int number = 9;
if (number % 2 == 0) {
System.out.println(“Even”);
} else {
System.out.println(“Odd”);
}
}
}
Importance of the Modulus Operator
The modulus operator supports:
- remainder calculations,
- divisibility checks,
- pattern generation,
- and program control.
3.5 Key Notes / Summary
- The modulus operator returns remainders.
- % is the modulus symbol in Java.
- Even numbers have zero remainder when divided by 2.
- Odd numbers produce a remainder when divided by 2.
- Modulus operations support divisibility checks.
- The modulus operator is useful in loops and conditions.