CL 9 Chapt 5 Computer Application
CL 9 Chapt 5 Computer Application
CLASS IX
Chapter 5
OPERATORS AND EXPRESSIONS
Presented by
Ms. Siva Shankari@CPSV
OPERATORS: 2
An operator is a symbol that
Example
5+3 here ‘+’ is an operator
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
Likewise count -- 10
Created BY, Siva Shankari @ CPSV
Relational
Operator
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
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:
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: