Arithmetic Operators in Java
The Java programming language supports various arithmetic operators for all floating-point and integer numbers. These operators are + (addition), - (subtraction), * (multiplication), / (division), and % (modulo).
- Addition(+): This operator is a binary operator and is used to add two operands.
- Subtraction(-): This operator is a binary operator and is used to subtract two operands.
- Multiplication(*): This operator is a binary operator and is used to multiply two operands.
- Division(/): This is a binary operator that is used to divide the first operand(dividend) by the second operand(divisor) and give the quotient as result.
- Modulus(%): This is a binary operator that is used to return the remainder when the first operand(dividend) is divided by the second operand(divisor).
Code Snippet
// Arithmetic Operators in Java
public class App {
public static void main(String args[]) {
int a = 123, b = 10;
System.out.println("Addition : " + (a + b));
System.out.println("Subtraction : " + (a - b));
System.out.println("Multiplication : " + (a * b));
System.out.println("Division : " + (a / b));
System.out.println("Modulus : " + (a % b));
}
}