Modulus And Assignment Operator Example Java Program

Definition

The modulo operation finds the remainder after division of one number by another (sometimes called modulus). Given two positive numbers, a (the dividend) and n (the divisor), a modulo n (abbreviated as a mod n) is the remainder of the Euclidean division of a by n.

Syntax

a %= b;

Modulus And Assignment Operator Example Program

class ModulusAndAssignmentOperator{
	public static void main(String[] args){
		int num1,num2;
		num1=13;
		num2=8;
		System.out.println("num1=13; num2=8");
		num1%=num2;
		System.out.println("The result after modulus operation is : "+num1);
	}
}

Sample Output

Output is 
num1=13; num2=8
The result after modulus operation is : 5