In this tutorial you will learn about the Java Arithmetic Operators and its application with practical example.
Java Arithmetic Operators
Arithmetic Operators are used to performing arithmetic operations like addition, subtraction, multiplication, division, %modulus, exponent, etc. Let variable a hold 20 and variable b hold 10, then −
Operator | Name | Description | Example |
---|---|---|---|
+ |
Addition |
Addition of given operands |
a+b returns 30 |
- |
Subtraction |
Subtraction of second operand from first |
a-b returns 10 |
* |
Multiply |
Multiplication of given operands |
a*b returns 200 |
/ |
Division |
Returns Quotient after division |
a/b returns 2 |
% |
Modulus |
Returns Remainder after division |
a%b returns 0 |
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public class Main { public static void main(String[] args) { int a= 20; int b= 10; System.out.println("W3Adda - Java Arithmetic Operators"); 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); } } |
When you run the above java program, you will see the following output.
Output:-