Explain the following with an example segment: Modulus Operator
Advertisements
Question
Explain the following with an example segment:
Modulus Operator
Code Writing
Explain
Advertisements
Solution
The Modulus Operator (%) in Java is an arithmetic operator used to find the remainder when one number is divided by another number.
It is commonly used to check whether a number is even or odd.
Example Code Segment:
int a = 10, b = 3;
int result = a % b;
System.out.println(result);
Output:
1
shaalaa.com
Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 131]
