Wednesday, June 10, 2015

Operators

8:15 AM

Operators

Operator is a special symbol that tells the compiler to perform specific mathematical or logical Operation. Java supports following lists of operators.
  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Ternary or Conditional Operators


Arithmetic Operators

Given table shows all the Arithmetic operator supported by Java Language. Lets suppose variable A hold 8 and B hold 3.


Operator                                  Example (int A=6, B=4)                                    Result
    +                                           A+B                                        10
    -                                           A-B                                         2
    *                                           A*B                                        24
    /                                           A/B                                         3
   %                                          A%4                                         0.24


Relational Operators

Which can be used to check the Condition, it always return true or false. Lets suppose variable A hold 8 and B hold 3.


Operators                    Example (int A=7, B=3)                                         Result
<                            A<BFalse
<=                           A<=10True
>                           A>BTrue
>=                          A<=BFalse
==                         A== BFalse
!=                               A!=(-4)True

Logical Operator

Which can be used to combine more than one Condition?. Suppose you want to combined two conditions A<B and B>C, then you need to use Logical Operator like (A<B) && (B>C). Here && is Logical Operator.
Operator              Example (int A=7, B=3, C=-11)                              Result
&&                (A<B) && (B>C)                               False
||               (B!=-C) || (A==B)                               True
!                    !(B<=-A)                                True

Truth table of Logical Operator

C1              C2                   C1 && C2         C1 || C2                  !C1                       !C2
TT      T              T                     F                         F
TF      F              T                     F                         T
FT      F              T                     T                           F
FF                             F              F                     T                          T

Assignment operators

Which can be used to assign a value to a variable. Lets suppose variable A hold 8 and B hold 3.
Operator                        Example (int A=9, B=4)                                    Result
+=                          A+=B or A=A+B                                        13
-=                           A-=3 or A=A-3                                        6
*=                        A*=7 or A=A*7                                        63
/=                         A/=B or A=A/B                                        2.25
%=                         A%=5 or A=A%5                                        0.45


Ternary operator

If any operator is used on three operands or variable is known as ternary operator. It can be represented with " ?: "

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

 

© 2013 Java Tutorials. All rights resevered. Designed by Templateism

Back To Top