Difference between object oriented object based programming language

What is modulus operator % in java ?

Answer : % is arithmatic modulus operator. When used it returns the remainder of the division operation. It can be applied to integer types and floating-point types as well. Please see example below of modulus (%) operator:

package com.javahonk.modulustest;

public class ModulusTest {

	public static void main(String[] args) {
		int x = 26;
		double y = 26.54;
		System.out.println("x mod 10 = " + x % 10);
		System.out.println("y mod 10 = " + y % 10);

	}

}

 

Output:
What is modulus operator

 

List of arithmetic operators:

ResultOperator
Addition+
Subtraction (also unary minus)
Multiplication*
Division/
Modulus%
Increment++
Addition assignment+=
Subtraction assignment–=
Multiplication assignment*=
Division assignment/=
Modulus assignment%=
Decrement– –

 

Leave a Reply

Your email address will not be published. Required fields are marked *