Arithmetic operators are symbols used to perform basic math operations like addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).
Click to reveal answer
beginner
What does the modulus operator (%) do?
The modulus operator (%) gives the remainder after dividing one number by another. For example, 7 % 3 equals 1 because 7 divided by 3 leaves a remainder of 1.
Click to reveal answer
beginner
What is the result of integer division in Java?
When dividing two integers, Java returns the quotient without the decimal part. For example, 7 / 3 equals 2, not 2.333.
Click to reveal answer
beginner
How do you perform multiplication in Java?
Use the asterisk (*) symbol between two numbers. For example, 4 * 5 equals 20.
Click to reveal answer
intermediate
What happens if you divide by zero in Java?
Dividing an integer by zero causes a runtime error called ArithmeticException. Dividing a floating-point number by zero results in Infinity or NaN.
Click to reveal answer
Which operator is used for addition in Java?
A*
B+
C-
D%
✗ Incorrect
The plus sign (+) is used for addition.
What is the output of 10 % 4 in Java?
A6
B0
C2
D4
✗ Incorrect
10 divided by 4 leaves a remainder of 2, so 10 % 4 equals 2.
What is the result of 9 / 2 when both are integers?
A4
B4.5
C5
D2
✗ Incorrect
Integer division truncates the decimal, so 9 / 2 equals 4.
Which operator multiplies two numbers?
A-
B+
C/
D*
✗ Incorrect
The asterisk (*) is used for multiplication.
What happens if you divide an integer by zero in Java?
AThrows ArithmeticException
BReturns Infinity
CReturns zero
DReturns NaN
✗ Incorrect
Dividing an integer by zero throws an ArithmeticException at runtime.
Explain the difference between division and modulus operators in Java.
Think about what happens when you divide numbers and what is left over.
You got /3 concepts.
Describe what happens when you use arithmetic operators on integers versus floating-point numbers in Java.
Consider how Java treats whole numbers and decimals differently.
You got /4 concepts.
Practice
(1/5)
1. Which of the following is the correct symbol for the modulus operator in Java, which gives the remainder of a division?
easy
A. *
B. /
C. -
D. %
Solution
Step 1: Understand the modulus operator
The modulus operator returns the remainder after division of two numbers.
Step 2: Identify the correct symbol in Java
In Java, the symbol for modulus is %.
Final Answer:
% -> Option D
Quick Check:
Modulus operator = % [OK]
Hint: Modulus operator is always % in Java math [OK]
Common Mistakes:
Confusing modulus % with division /
Using * or - instead of %
Thinking modulus returns quotient
2. Which of the following Java statements correctly calculates the product of two integers a and b?
easy
A. int result = a / b;
B. int result = a + b;
C. int result = a * b;
D. int result = a % b;
Solution
Step 1: Identify the multiplication operator
In Java, the multiplication operator is *.
Step 2: Check the statement that uses multiplication
The statement int result = a * b; correctly multiplies a and b.
Final Answer:
int result = a * b; -> Option C
Quick Check:
Multiplication operator = * [OK]
Hint: Use * for multiplication in Java expressions [OK]
Common Mistakes:
Using + instead of * for multiplication
Confusing division / with multiplication
Using % which is remainder, not product
3. What is the output of the following Java code?
int x = 10;
int y = 3;
System.out.println(x / y);
medium
A. 3
B. 3.3333333
C. 3.0
D. 4
Solution
Step 1: Understand integer division in Java
Both x and y are integers, so division drops the decimal part.
Step 2: Calculate integer division result
10 divided by 3 is 3.333..., but integer division returns 3.
Final Answer:
3 -> Option A
Quick Check:
Integer division drops decimals = 3 [OK]
Hint: Integer division drops decimals, result is integer [OK]
Common Mistakes:
Expecting decimal output with int division
Confusing / with % operator
Assuming automatic float conversion
4. Identify the error in the following Java code snippet:
int a = 5;
int b = 0;
int c = a / b;
System.out.println(c);
medium
A. Division by zero causes runtime error
B. Variable c is not declared
C. Missing semicolon after declaration
D. Incorrect use of modulus operator
Solution
Step 1: Analyze the division operation
The code divides a by b, where b is zero.
Step 2: Understand division by zero in Java
Dividing an integer by zero causes a runtime ArithmeticException error.
Final Answer:
Division by zero causes runtime error -> Option A
Quick Check:
Division by zero throws error [OK]
Hint: Never divide by zero; it crashes the program [OK]
Common Mistakes:
Ignoring division by zero error
Thinking it returns zero or infinity
Confusing syntax error with runtime error
5. Given the code below, what will be the value of result after execution?
int a = 15;
int b = 4;
int result = a / b + a % b * 2;