0% found this document useful (0 votes)
5 views26 pages

CL 9 Chapt 5 Computer Application

operators and expressions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views26 pages

CL 9 Chapt 5 Computer Application

operators and expressions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

COMPUTER APPLICATION

CLASS IX

Chapter 5
OPERATORS AND EXPRESSIONS

Presented by
Ms. Siva Shankari@CPSV
OPERATORS: 2
 An operator is a symbol that

tells the computer to perform


some operations.
 The operation may be to add,

subtract, divide etc.

Example
 5+3 here ‘+’ is an operator

which tells the computer to


TYPES OF OPERATORS 3

Arithmetic operators- carry out


arithmetic expressions (+, - , *, /, %)
Relational operators – specify
relation between two values or
expressions(<, >, <=, >=,==, <>)
Logical operators – combine two or
more relational expressions.(&&, ||, !)
Other operators - (?:, new, .(dot))
Arithmetic
4
Operators Unary operator
 Unary + : it
 Binary precedes an
operators: it operand
requires two  If a=5 the +a
means 5
values to  Unary - : it
 If a = -4 then
precedes an +a
calculate means -4
operand
 Unary  If a=5 the -a
operators: it means -5
require only  If a = -4 then -a
means -4
Binary operator
Created BY, Siva Shankari @ CPSV

Arithmetic operator
Binary operator
The symbols that performs arithmetic operations
on the values or variables are called arithmetic
operators.
Created BY, Siva Shankari @ CPSV

Arithmetic operator
operators + with
String
5 + 6 results into 11
“5” + “6” results into 56
“17” + “V. Vinoth” results into 17V.
Vinoth
5 + “abc” results into 5abc
 public class calc Increment /
 { Decrement(++, --)
 int a=17,b=3;  Prefix
 int q, r;  Postfix
 q=a/b; Prefix operation: ( Change
 r=a%b; then use)
 System.out.println(“for This operator precedes its
5/3”) operand before using the value
System.out.println(“quotie of the operand.
nt =” +q);
Example: sum=sum+(++
 System.out.println(“remain count); //count=10
der= ” +r);
Sum=sum+11 => 0+11=11
 }
Sum=11
9

Example: Postfix operation: (use then


change)
Evaluate X=++y + 2y if y=6 This operator precedes its
operand after using the value
Solution: initially y=6 of the operand.
X= 7+2*7 Example: sum=sum+(count+
X=7+14 +); //count=10
X=21 Sum=sum+10 => 0+10=10
Sum=10

Likewise count --  10
Created BY, Siva Shankari @ CPSV

Relational
Operator

 The symbols that establish


a relationship between two
variables or literals or a
variable, literal or an
expression are called
arithmetic operators.
 The result for relational
expression is either true or
false.
 An expression is a
combination of operands
and operators that yields a
result. This result can be
stored in another variables
Relational Operator
p q P<q P<=q P==q P>q P>=q P!=q

0 1 T T F F F T

1 0 F F F T T T

2 2 F T T F T F

3 6 T T F F F T
Created BY, Siva Shankari @ CPSV

Logical Operator

 The symbols that


performs logical
operations on the result
of the relational
expressions are called
Logical operators.
 The result for Logical
expression is either true
or false.
 Syntax:
op1 logical
operator op2
Created BY, Siva Shankari @ CPSV

Logical Operator
14
Assignment Operator
The assignment operator
assigns a value or result of
an expression to a variable.
The common assignment
operator is ‘=‘
 Example:
i)x=y, here x gets the sum of y
and z
ii)x=y + z, here x get the sum
Shorthand assigment:

a=a + 1 shorthand assignment operator to


simplify the statement as a+=1 which
means a=a+1.
Conditional operator:
This operator is also called as ternary import java.io.*;
operator i.e, it requires three public class greater
operands. {
public static void main()
Syntax: {
expression1?expression2: int a=4, b=25;
expression3 int result=a>b? a: b;
System.out.println(result);
example: }
result= marks>=50? “pass” : “fail”; }

Output:
25
New operator: import java.io.*;
you use new operator to create object public class emp
of a class. {
Public void detail()
Syntax: {
classname obj name=new String name=“arun”;
classname(); int salary= 10000;
System.out.println(“name=” +name);
System.out.println(“salary=” +salary);
example:
}
emp oe=new emp(); public static void main()
{
emp oe=new emp();
oe.detail();
}
}
import java.io.*;
dot operator: public class emp
{
once memory of an object is
Public void detail()
allocated using new operator, you {
can access individual data members String name=“arun”;
of an object using dot operator. int salary= 10000;
Syntax: System.out.println(“name=” +name);
objname.methodname System.out.println(“salary=” +salary);
objname.variable }
classname.variable public static void main()
{
example: emp oe=new emp();
oe.detail(); oe.detail();
}
emp.name;
}
OPERATOR PRECEDENCE
Expressions:

an expression is composed of one or Some commonly used


more operations. The objects of the expressions are related to math
operations referred to as operands. functions
The expressions can be of any type.
1. Arithmetic  Pow(x,y)
2. Relational  Log(x)
3. Logical  Sqrt(x)
 Abs)x)
Implicit conversion
Explicit conversion
Thankyou

You might also like