Java - Basic Operators - Clemson University

JAVA - BASIC OPERATORS



Copyright ? tutorials

Java provides a rich set of operat ors t o manipulat e variables. We can divide all t he Java operat ors int o t he following groups:

Arit hmet ic Operat ors Relat ional Operat ors Bit wise Operat ors Logical Operat ors Assignment Operat ors Misc Operat ors

The Arit hmet ic Operat ors:

Arit hmet ic operat ors are used in mat hemat ical expressions in t he same way t hat t hey are used in algebra. The following t able list s t he arit hmet ic operat ors: Assume int eger variable A holds 10 and variable B holds 20, t hen: Show Examples

O perat o r

Desc ript io n

+

Addit ion - Adds values on eit her side of t he operat or

-

Subt ract ion - Subt ract s right hand operand from left hand

operand

*

Mult iplicat ion - Mult iplies values on eit her side of t he operat or

/

Division - Divides left hand operand by right hand operand

%

Modulus - Divides left hand operand by right hand operand and

ret urns remainder

++

Increment - Increases t he value of operand by 1

--

Decrement - Decreases t he value of operand by 1

Example A + B will give 30 A - B will give -10

A * B will give 200 B / A will give 2 B % A will give 0

B++ gives 21 B-- gives 19

The Relat ional Operat ors:

There are following relat ional operat ors support ed by Java language Assume variable A holds 10 and variable B holds 20, t hen: Show Examples

O perat o r

Desc ript io n

==

Checks if t he values of t wo operands are equal or not , if yes

t hen condit ion becomes t rue.

!=

Checks if t he values of t wo operands are equal or not , if values

are not equal t hen condit ion becomes t rue.

Example (A == B) is not t rue. (A != B) is t rue.

>

Checks if t he value of left operand is great er t han t he value of

(A > B) is not

right operand, if yes t hen condit ion becomes t rue.

t rue.

<

Checks if t he value of left operand is less t han t he value of right (A < B) is t rue.

operand, if yes t hen condit ion becomes t rue.

>=

Checks if t he value of left operand is great er t han or equal t o

(A >= B) is not

t he value of right operand, if yes t hen condit ion becomes t rue. t rue.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download