← Back to Chapters

Java Arithmetic Operators

➕ Java Arithmetic Operators

? Quick Overview

Arithmetic operators in Java are used to perform basic mathematical operations such as addition, subtraction, multiplication, division, and modulus. These operators work mainly with numeric data types like int, float, double, and long.

? Key Concepts

  • Operate on numeric values
  • Return calculated results
  • Follow operator precedence rules
  • Used in calculations, conditions, and logic

? Syntax / Theory

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulus (remainder)
? View Code Example
// Demonstration of Java arithmetic operators
public class ArithmeticDemo {
public static void main(String[] args) {
int a = 10;
int b = 3;

System.out.println(a + b);
System.out.println(a - b);
System.out.println(a * b);
System.out.println(a / b);
System.out.println(a % b);
}
}

?️ Live Output / Explanation

The program performs arithmetic operations on two integers. Division returns an integer result because both operands are integers. The modulus operator returns the remainder after division.

✅ Tips & Best Practices

  • Use double for accurate division results
  • Be careful with division by zero
  • Use parentheses to control operator precedence

? Try It Yourself

  • Change variables to double and observe division output
  • Add user input using Scanner
  • Try combining multiple arithmetic operations