You are on page 1of 19

OPERATORS

COMPUTER PROGRAMMING <COM01>


OPERATORS
● symbols that represent
simple computations.
● used to perform
operations on variables
and values.
JAVA
OPERATORS
● Arithmetic
● Assignment
● Comparison
● Logical
● Bitwise and Shift
ARITHMETIC
OPERATORS
● used to perform common
mathematical operations.
ARITHMETIC OPERATORS
Operator Name Description Example

+ Addition Adds together two values x+y

- Subtraction Subtracts one value from another x-y

* Multiplication Multiplies two values x*y

/ Division Divides one value by another x/y

% Modulus Returns the division remainder x%y

++ Increment Increases the value of a variable by x++


1

-- Decrement Decreases the value of a variable by x--


1
ASSIGNMENT
OPERATORS
● used to assign values to
variables while operating
the value.
ASSIGNMENT OPERATORS
Operator Example Same As

= x=5 x=5

+= x += 3 x=x+3

-= x -= 3 x=x-3

*= x *= 3 x=x*3

/= x /= 3 x=x/3

%= x %= 3 x=x%3

&= x &= 3 x=x&3

|= x |= 3 x=x|3

^= x ^= 3 x=x^3

>>= x >>= 3 x = x >> 3

<<= x <<= 3 x = x << 3


COMPARISON
OPERATORS
● used to compare two
values
● return value of a either
true or false
COMPARISON OPERATORS
Operator Name Example

== Equal to x == y

!= Not equal x != y

> Greater than x>y

< Less than x<y

>= Greater than or equal to x >= y

<= Less than or equal to x <= y


LOGICAL
OPERATORS
● used to determine the
logic between variables or
values
LOGICAL OPERATORS
Operator Name Description Example

&& Logical and Returns true if both statements x < 5 && x < 10
are true

|| Logical or Returns true if one of the x < 5 || x < 4


statements is true

! Logical not Reverse the result, returns false if !(x < 5 && x < 10)
the result is true
BITWISE
OPERATORS
● perform operations on
integer data at the
individual bit-level
BITWISE OPERATORS
Operator Description

| Bitwise OR

& Bitwise AND

^ Bitwise XOR

~ Bitwise Complement

<< Left Shift

>> Signed Right Shift

>>> Unsigned Right Shift


CONDITIONAL
STATEMENTS
COMPUTER PROGRAMMING <COM01>
CONDITIONAL
STATEMENTS
● statements which
evaluates actions in
the program and
evaluates if it's true or
false
if
Used specify a block of Java code to be executed if a condition is
true
else if
statement to specify a new condition if the first condition is
false
else
Used specify a block of Java code to be executed if a condition is
false
switch
statement selects one of many code blocks to be executed

You might also like