Skip to content
C

Arithmetic Operators

Arithmetic operators are symbols used to perform basic mathematical calculations in Java — addition, subtraction, multiplication, division, and finding the remainder of a division.


1. What are Arithmetic Operators?

Arithmetic operators are symbols used to perform basic mathematical calculations in Java — addition, subtraction, multiplication, division, and finding the remainder of a division.

2. Why is it used?

Almost every program needs to calculate something — a total bill, an average score, or a remaining balance. Arithmetic operators are the basic building blocks for all such calculations.

3. Real-Life Example

Think of a shopkeeper's calculator. Every time a customer buys something, the shopkeeper adds prices, subtracts a discount, or multiplies the price by quantity. Arithmetic operators do exactly this kind of work inside a Java program.

4. Syntax

java
int sum = a + b; int difference = a - b; int product = a * b; int quotient = a / b; int remainder = a % b;

5. Example Program

java
public class ArithmeticDemo { public static void main(String[] args) { int a = 17, b = 5; System.out.println("Sum: " + (a + b)); System.out.println("Difference: " + (a - b)); System.out.println("Product: " + (a * b)); System.out.println("Quotient: " + (a / b)); System.out.println("Remainder: " + (a % b)); } }

Output:

Sum: 22
Difference: 12
Product: 85
Quotient: 3
Remainder: 2

6. Key Points to Remember

  • % gives the remainder, not a percentage — a common confusion for beginners.
  • Dividing two integers gives an integer result; decimals are dropped (e.g., 7 / 2 gives 3, not 3.5).
  • To get a decimal result, at least one value involved must be a double or float.

Mock Test

  • Arithmetic Operators - Quick Test

    10 questions on +, -, *, /, % and how integer arithmetic behaves in Java.

    10 questions · 10 min · Easy
    Start Mock Test

Coding Problems