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.
// 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);
}
}
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.
double for accurate division resultsdouble and observe division outputScanner