Java Arithmetic Operators :
Java arithematic operators is explained in this part of the tutorial with the help of operators and variables.These operators are used in mathematical operators mostly they are numeric.
These operands cannot be used on other data types because they are only supported by numeric and also char variable.
- Addition Operator (+)
- Subtraction Operator (-)
- Division Operator (/)
- Multiplication Operator (*)
- Percentile Operator (%)
- Increment Operator (++)
- Decrement Operator (–)
Now lets get through each of these and way of using them through a small example and see the result
Addition (+) :
Adding up of two numbers is done with the help of this operand let’s start coding by initializing variables
public static int a; public static int b; public static int result;
assign values to the variables
a = 10; b = 20;
then make the operation possible on them with the help of operand
result = a + b;
now print the output using System.out.println
// addition operation a = 10; b = 20; result = a + b; System.out.println(result);
Simple subtraction of two numbers is shown with the help of operand and variables.
// substraction operation a = 20; b = 10; result = a - b; System.out.println(result);
Division operand is explained with the help of a example.
// division operation a = 10; b = 2; result = a / b; System.out.println(result);
Multiply of two numbers in java using ‘*’ operand is shown
// multiplication operation a = 10; b = 10; result = a * b; System.out.println(result);
Percentile of two number is calculated here
// percentage operation a = 100; b = 5; result = b % a; System.out.println(result);
Increment Operator (++):
Incrementing a number is show here we mostly use them in loops
// incremental operation a = 10; result = ++a; System.out.println(result);
Decrement (- -):
Decrement operator is explained here with a example
// decremental operation a = 15; result = --a; System.out.println(result);
Any query on Java Arithmetic Operators let us know in the comment section below.
For more interesting tutorials do like and share this tutorial.