Professional Documents
Culture Documents
BASIC
PERATORS
I T 2 1 3
2
What are Operators?
Arithmetic
Assignment
operators
operators
Types of operators
Unary Relational
Operators operators
ARITHMETIC
OPERATORS
5
Arithmetic Operators
Operators Operation
+ Addition
- Subtraction
* Multiplication
/ Division
% Computes the remainder
Arithmetic Operators
1. Expressions in parentheses
2. Multiplication, Division and Modulus from left to right
3. Addition and subtraction, from left to right
Operators Operation
+= Addition
-= Subtraction
*= Multiplication
/= Division
%= Computes the remainder
UNARY
OPERATORS
11
UNARY OPERATORS
Unary operators are used with Operator Meaning
only one operand.
Unary plus: not
Example: ++ is a unary operator that +
necessary to use since
increases the value of a variable by 1. numbers are positive
without using it
++5 will return 6.
Unary minus: inverts
INCREMENT and DECREMENT - the sign of an
OPERATORS expression
• Java also has unary increment
++
Increment operator:
and decrement operators that increments value by 1
increase or decrease the value
of a variable by 1 Decrement operator:
--
decrements value by 1
• where operand1 could be any
literal or variable name
INCREMENT
OPERATORS
13
Types of Increment Operators
Example: ++a;
Example: a++;
DECREMENT
OPERATORS
15
Types of Decrement Operators
Example: --a;
Example: a--;
RELATIONAL
OPERATORS
17
RELATIONAL OPERATORS
Not Equal To Evaluates as true when both operands are not 3 != 5 returns
!=
equal true
Greater Than Evaluates as true when the left operand is greater 3 >= 5 returns
>=
or Equal To than or equal to the right operand false
Less Than or Evaluates as true when the left operand is less 3 <= 5 returns
<=
Equal To than or equal to the right operand true
Exercise - Relational Operators
1. a > b
2. b <= c
3. c != d
LOGICAL
OPERATORS
21
LOGICAL OPERATORS
• sometimes called a “Boolean operator”