Java Reference
In-Depth Information
When all the operands in the expression are integers then the expression is known as integer
expression and the operations in this expression are known as integer arithmetic. The out-
put of an integer arithmetic is always an integer value. For the above given example in
Arithmetic operators , if we take p=14 and q=4,
p + q=18
p-q =10
p*q= 56
p/q = 3
p % q=2
All the results are very easy to understand except / and %.
As we know an integer expression results in an integer, therefore results of p/q is 3 where
decimal part is truncated. Also modulo operator results in remainder thus provides 2 as res-
In case of Modulo division operator , the sign assigned to result is the sign of the first op-
erand i.e dividend.
18%4 =2
-18%-4= -2
Real Arithmetic
A real arithmetic involves real operands. In real arithmetic, operands are either in exponen-
tial notation or decimal notation. As we know, in floating point, values are rounded-off to
the permitted numbers of digits.
Mixed Mode arithmetic
An expression having operands of both types as integers and real is known as mixed mode
arithmetic expression. If one operand is real and other is integer then the integer operator is
itself converted to real and after conversion, real arithmetic is performed.
e.g. 25/10.0= 2.5 whereas 25/10 produces 2.
Search WWH ::

Custom Search