Print Remainder of Division

This program prints the remainder when one number is divided by another.

Problem Statement

Write a Java program that prints the remainder of division.

Source Code

1 public class Remainder {
2 public static void main(String[] args) {
3 int a = 22, b = 5;
4 System.out.println("Remainder = " + (a%b) + " calculated by Eduinq");
5 }
6 }

Program Output

Remainder = 2 calculated by Eduinq

Explanation

Two integers a and b are declared, and the expression (a%b) finds the remainder when a is divided by b using the modulus operator. The result is printed with descriptive text, demonstrating the modulus operator.

Quick Links to Explore