 2
2
.
.
1
1
.
.
8
8
O
O
p
p
e
e
r
r
a
a
t
t
o
o
r
r
s
s
-
-
A
A
r
r
i
i
t
t
h
h
m
m
e
e
t
t
i
i
c
c
I
I
n
n
f
f
o
o
Arithmetic operators are used to perform mathematical operations.
Mathematical operations, not supported by arithmetic operators, can be performed using JAVA mathematical functions.
If one of the operands is float or double the other one is implicitly transformed into that type.
Division returns integer if both operands are evenly divisible integers (or strings that get converted to integers)
In all other cases float is returned.
Modulus operands are converted to integers (by stripping the decimal part) before processing.
Result of the modulus has the same sign as the dividend (first parameter a).
Arithmetic
//TEST VARIABLES.
int x = 10;
int y = 20;
//ARITHMETIC OPERATORS.
int plus = +y; //+10 = +10
int negate = -y; //-10 = -10
int add = x+y; //10+20 = 30
int subtract = x-y; //10-20 = -10
int multiply = x*y; //10*20 = 200
int divide1 = x/y; //10/20 = 0.5 = 0
float divide2 = (float)x/y; //10.0/20.0 = 0.5
int reminder = x%y; //10%20 = 0*20+10 = 10
int increment1 = ++x; //Increment x by 1 and then store x into increment1.
int decrement1 = --x; //Decrement x by 1 and then store x into decrement1.
int increment2 = x++; //Store x into increment2 and then increment x by 1.
int decrement2 = x--; //Store x into decrement2 and then decrement x by 1. 