OPERATORS
What is operators?
● Operators are predefined symbol which is used to perform some
specific task on the given data.the data given as a input to the
operator is known as operand.
TYPES OF OPERATORS BASED ON OPERAND:
● UNARY OPERATOR
● BINARY OPERATOR
● TERNARY OPERATOR
UNARY OPERATOR :
The operator which can accept only one operand
is known as unary operator.
Example : Increment/Decrement operator.
BINARY OPERATOR:
The operator which can accept two operand is known
as binary operator.
Example : Arithmetic operator,relational operators.
TERNARY OPERATOR:
The operator which can accept three operand is
known as ternary operator.
Example : Conditional Operator
CLASSIFICATION OF OPERATOR BASED ON TASK:
● ARITHMETIC OPERATOR
● ASSIGNMENT OPERATOR
● RELATIONAL OPERATOR
● LOGICAL OPERATOR
● INCREMENT/DECREMENT OPERATOR
● CONDITIONAL OPERATOR
MISCELLANEOUS
ARITHMETIC OPERATOR
‘+’ Operator:
+
ADDITION
CONCAT
ACTIVITY:
1.Write a java program to perform addition of two numbers.
2.Write a java program to concat a number and String.
3.Write a java program to concat a floating number and String.
4.Write a java program to concat a integer and character.
5.Write a java program to concat a character and String.
6.Write a java program to concat a integer,character,boolean and
String data.
ASSIGNMENT OPERATOR:
Assignment operators are used in Java to assign values to variables.
1. +=
2. -=
3. *=
4. /=
Operator Example Equivalent to
= a=b; a=b;
+= a+=b; a=a+b;
- -= a-=b; a=a-b;
Operator Example Equivalent to
*= a*=b; a=a*b;
/= a/=b; a=a/b;
%= a%=b; a=a%b;
RELATIONAL OPERATORS:
● < - lesser than
● > - greater than
● <= - lesser than or equal to
● >= - greater than or equal to
● == - equal to
● != - not equal to
NOTE :
The return value of relational operator is boolean.
LOGICAL OPERATOR:
&&(Logical AND)
If all the expression returns true then this operator will
return true
||(Logical OR)
If any of one of the expression return true then this operator
will return true
! (Logical NOT)
It the result is true then it will return false and vice versa
TRUE TRUE TRUE
TRUE FALSE FALSE
FALSE TRUE FALSE
FALSE FALSE FALSE
AND TABLE :
OR TABLE :
TRUE TRUE TRUE
TRUE FALSE TRUE
FALSE TRUE TRUE
FALSE FALSE FALSE
INCREMENT/DECREMENT OPERATOR
Increment Operator:
● Pre-Increment Operator
● Post-Increment Operator
Decrement Operator:
● Pre-Decrement Operator
● Post-Decrement Operator
INCREMENT OPERATOR
PRE-INCREMENT (++VAR) POST-INCREMENT(VAR++)
● INCREMENT THE
VALUE BY 1
● USE THE
UPDATED VALUE
● USE THE OLD
DATA
● INCREMENT THE
VALUE BY 1
DECREMENT OPERATOR
PRE- DECREMENT(--VAR) POST- DECREMENT(VAR- -)
● DECREMENT THE
VALUE BY 1
● USE THE
UPDATED VALUE
● USE THE OLD
DATA
● DECREMENT THE
VALUE BY 1
Conditional Operator:
SYNTAX:
Operand 1 ? Operand 2 : Operand 3
(Condition) ? value1 : value2
Working of Conditional Operator:
CONDITION ? VALUE1 VALUE2
:
TRUE
FALSE
● Conditional Operator will check the condition,if
condition is true operand 2 will gets executed,if
condition is false operand 3 ill gets executed.
Note :
● The return value of conditional operator is always
boolean.
● The return value of operand 1 is based on operand
2 and operand 3.
EXAMPLE:
Class Demo
{
public static void main(String[] args)
{
int a = 10;
int b =20;
int c = (a>b) ? a : b; //Conditional Operator
System.out.println(c); // 20
}
}
TRACE THE PROGRAMS: (INCREMENT OPERATOR)
1.int a=10;
a++;
s.o.p(a);
2.int b =20;
++b;
s.o.p(b);
3.int a=10;
a=a++;
s.o.p(a);
4.int d =40;
int e = 50;
d = d++ + ++e;
s.o.p(d);
5.short s = 20;
byte b = 25;
s++;
++b;
s.o.p(s+b);
6. int a1=100;
short a2 = 150;
int a3 = 350;
long a4 = 200;
long res = a1++ - ++a2 +a3++ - ++a4;
s.o.p(res);
1.int a=35;
a - - ;
s.o.p(a);
2.int b = 70;
- -b;
s.o.p(b);
TRACE THE PROGRAMS: (DECREMENT OPERATOR)
3.int a=100;
a= a- -;
s.o.p(a);
4.int d =76;
int e = 32;
d = d- - + - -e;
s.o.p(d);
5. int a1=100;
short a2 = 150;
int a3 = 350;
long a4 = 200;
int res = a1- - - ++a2 + a3- - - ++a4;
s.o.p(res);

10)OPERATORS.pdf

  • 1.
  • 2.
    What is operators? ●Operators are predefined symbol which is used to perform some specific task on the given data.the data given as a input to the operator is known as operand. TYPES OF OPERATORS BASED ON OPERAND: ● UNARY OPERATOR ● BINARY OPERATOR ● TERNARY OPERATOR
  • 3.
    UNARY OPERATOR : Theoperator which can accept only one operand is known as unary operator. Example : Increment/Decrement operator.
  • 4.
    BINARY OPERATOR: The operatorwhich can accept two operand is known as binary operator. Example : Arithmetic operator,relational operators.
  • 5.
    TERNARY OPERATOR: The operatorwhich can accept three operand is known as ternary operator. Example : Conditional Operator
  • 6.
    CLASSIFICATION OF OPERATORBASED ON TASK: ● ARITHMETIC OPERATOR ● ASSIGNMENT OPERATOR ● RELATIONAL OPERATOR ● LOGICAL OPERATOR ● INCREMENT/DECREMENT OPERATOR ● CONDITIONAL OPERATOR MISCELLANEOUS
  • 7.
  • 8.
  • 9.
    ACTIVITY: 1.Write a javaprogram to perform addition of two numbers. 2.Write a java program to concat a number and String. 3.Write a java program to concat a floating number and String. 4.Write a java program to concat a integer and character. 5.Write a java program to concat a character and String. 6.Write a java program to concat a integer,character,boolean and String data.
  • 11.
    ASSIGNMENT OPERATOR: Assignment operatorsare used in Java to assign values to variables. 1. += 2. -= 3. *= 4. /=
  • 12.
    Operator Example Equivalentto = a=b; a=b; += a+=b; a=a+b; - -= a-=b; a=a-b;
  • 13.
    Operator Example Equivalentto *= a*=b; a=a*b; /= a/=b; a=a/b; %= a%=b; a=a%b;
  • 14.
    RELATIONAL OPERATORS: ● <- lesser than ● > - greater than ● <= - lesser than or equal to ● >= - greater than or equal to ● == - equal to ● != - not equal to
  • 15.
    NOTE : The returnvalue of relational operator is boolean.
  • 16.
    LOGICAL OPERATOR: &&(Logical AND) Ifall the expression returns true then this operator will return true ||(Logical OR) If any of one of the expression return true then this operator will return true ! (Logical NOT) It the result is true then it will return false and vice versa
  • 17.
    TRUE TRUE TRUE TRUEFALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE AND TABLE :
  • 18.
    OR TABLE : TRUETRUE TRUE TRUE FALSE TRUE FALSE TRUE TRUE FALSE FALSE FALSE
  • 19.
    INCREMENT/DECREMENT OPERATOR Increment Operator: ●Pre-Increment Operator ● Post-Increment Operator Decrement Operator: ● Pre-Decrement Operator ● Post-Decrement Operator
  • 20.
    INCREMENT OPERATOR PRE-INCREMENT (++VAR)POST-INCREMENT(VAR++) ● INCREMENT THE VALUE BY 1 ● USE THE UPDATED VALUE ● USE THE OLD DATA ● INCREMENT THE VALUE BY 1
  • 21.
    DECREMENT OPERATOR PRE- DECREMENT(--VAR)POST- DECREMENT(VAR- -) ● DECREMENT THE VALUE BY 1 ● USE THE UPDATED VALUE ● USE THE OLD DATA ● DECREMENT THE VALUE BY 1
  • 22.
    Conditional Operator: SYNTAX: Operand 1? Operand 2 : Operand 3 (Condition) ? value1 : value2
  • 23.
    Working of ConditionalOperator: CONDITION ? VALUE1 VALUE2 : TRUE FALSE
  • 24.
    ● Conditional Operatorwill check the condition,if condition is true operand 2 will gets executed,if condition is false operand 3 ill gets executed. Note : ● The return value of conditional operator is always boolean. ● The return value of operand 1 is based on operand 2 and operand 3.
  • 25.
    EXAMPLE: Class Demo { public staticvoid main(String[] args) { int a = 10; int b =20; int c = (a>b) ? a : b; //Conditional Operator System.out.println(c); // 20 } }
  • 27.
    TRACE THE PROGRAMS:(INCREMENT OPERATOR) 1.int a=10; a++; s.o.p(a); 2.int b =20; ++b; s.o.p(b); 3.int a=10; a=a++; s.o.p(a); 4.int d =40; int e = 50; d = d++ + ++e; s.o.p(d);
  • 28.
    5.short s =20; byte b = 25; s++; ++b; s.o.p(s+b); 6. int a1=100; short a2 = 150; int a3 = 350; long a4 = 200; long res = a1++ - ++a2 +a3++ - ++a4; s.o.p(res);
  • 29.
    1.int a=35; a -- ; s.o.p(a); 2.int b = 70; - -b; s.o.p(b); TRACE THE PROGRAMS: (DECREMENT OPERATOR) 3.int a=100; a= a- -; s.o.p(a); 4.int d =76; int e = 32; d = d- - + - -e; s.o.p(d);
  • 30.
    5. int a1=100; shorta2 = 150; int a3 = 350; long a4 = 200; int res = a1- - - ++a2 + a3- - - ++a4; s.o.p(res);