Sunteți pe pagina 1din 2

Arithmetic Operators and Logical Operators

Unary Plus(+)
UNARY
The operator unary plus (+) is written before the operand.
-Operates on only one operand,
e.g., -x, ++x, --x (the element is x). This operator results in the same value of the variable.
Binary

-Operates on two operands values, e.g.,


x + y (the elements are x and y).

OPERATORS Unary Minus(-)

-Operators are symbols that perform logical or mathematical The operator unary minus (-) also precedes an operand.
functions on operands such as variables, constants, and objects.
This operator inverts the value of an operand,
OPERANDS
i.e. if an operand value, it converts the value of that
-Operands are data values involved in the operation.
operand to its negative value and vice-versa

. Arithmetic Operators

- Arithmetic Operators are used to perform


The valid combination of both operands and operators
basic mathematical calculations, i.e., Addition (+),
make an expression, which returns a computed result.
Subtraction (-), Multiplication (*), Division(/), and
remainder (%).

Each of these operators are considered as


binary arithmetic operators, because they require Increment/Decrement Operators
two operands to performed.
-Increment (++) and Decrement (--) operators are used

to increase or decrease the value stored in

Java Operators a variables by 1 respectively.

-Java Operators can be classified as unary, or binary.

Modulo variable will get the remainder when x is


divided by y.
The increment (++) and decrement (--) operators can be Suffix Decrement(x--) Example 1
(Result of Example 3)
used both as PREFIX and SUFFIX. It evaluates the expression, and

Prefix Increment(++x) then decreases the value of operand by 1.

When an increment operator precedes its operand,

it is known as PREFIX increment.

++a
It increases the value of operand by 1, LOGICAL OPERATIONS
Relational Operators
and then evaluates the expression. -A logical operation is a special
-Relational operators are used to show
symbol or word which connects two
the relationship among the operands. Example 2
or more phrases of information.
-These operators compare -It is most often used to test
the values of variables and determine whether a certain relationship
the result in the boolean expression, between the phrases is true or

Prefix Decrement(--x) false.


either true or false.
-They give result in the form of true
It decreases the value of operand by 1, or false, depending upon the
and then evaluates the expression outcome of different relational
expressions.
Logical operators are further
categorized as:

Example 3

Suffix Increment(x++)
When an increment operator follows its operand, it
is known as SUFFIX increment.

a++
It evaluates the expression, and then increases the
value of operand by 1.

S-ar putea să vă placă și