Single Choice
Easy
QIf a is 10 and b is 3, what is the result of the expression a % b using the modulus operator in Java?
ID: #20124
Arithmetic Operators in Java
108 views
Question Info
#20124Q ID
EasyDifficulty
Arithmetic Operators in JavaTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer
Explanation
The modulus operator (%) in Java returns the remainder of the division of two numbers. In this case, 10 % 3 equals 1.
public class ModulusExample { public static void main(String[] args) { // Define the numbers int a = 10; int b = 3; // Calculate the result using the modulus operator int result = a % b; // Display the result System.out.println("Result of " + a + " % " + b + " is: " + result); } }
When you run this program, it will output:
Result of 10 % 3 is: 1
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic