SlideShare a Scribd company logo
5
Most read
8
Most read
9
Most read
Chapter 7
Java Basics
(Part 2 – Operators in java)
Presented by nuzhat memon
Operat
ors
1.
Arithme
tic
Operato
rs
2.
Compari
son
operato
rs
3.
Logical
Operato
rs
4.
Conditio
nal
operato
rs
5.
Assignm
ent
operato
r
Chapter 7
Java Basics
(Part 2 – Operators in java)
Presented by nuzhat memon
Operator
s
1.
Arithmetic
Operators
2.
Comparison
operators
3. Logical
Operators
4.
Conditional
operators
5.
Assignment
operator
Presented by Nuzhat Memon
Operators
+ Operators are special symbols used to build an expression.
3
Operators
1.
Arithmetic
Operators
2.
Comparison
operators
3. Logical
Operators
4.
Conditional
operators
5.
Assignment
operator
Presented by Nuzhat Memon 4
Basic arithmetic
operators are +, – , *,
/ , % (Modulus)
All these operators are
binary, they take 2
operands.
Used for byte, short, int,
long, float, double and
char (treated as int)
Arithmetic Operators
Operator Meaning Eg
+ Addition 2+8
– Subtraction 2-8
* Multiplication 2*8
/ Division 8/2
% Reminder 8%3
++ & -- is known
as unary operators
++ is increment
operator (which
adds 1) and -- is
decrement
operator (which
subtracts 1)
Increment / Decrement
Operators
++x pre-increment
--x pre-decrement
x++ post -increment
x-- post-decrement
Comparison
operators are
known as
relational
operators.
The result of
expression is
boolean; either
true or false
Comparison Operators
Operator Meaning
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
== Equal to
!= Not equal to
Logical operators
known as boolean
operators.
Logical operators:
AND, OR, XOR
(Exclusive OR),
NOT
Logical Operators
Operator Sign Use
AND && Used to combine two values
OR || Used to combine two values
XOR ^
It returns true only if operands
are different
NOT !
Operant is true, result is false
& vice versa
Also known as ternary
operator.
Conditional operator
uses 3 operands.
It uses two symbols ?
and : in the expression.
Syntax : (boolean-expr)
? (expr1) : (expr2)
To assign a value to
variable by using
the assignment
operator ‘=’
Syntax: <variable>
= <expression>;
Variable on lefthand
side of expression is
lvalue (location in
memory)
Conditional
Operator
Operators
Arithmetic
Operator
Increment and
Decrement
Operator
Comparison
Operator
Logical
Operator
Assignment
Operator
Operator
Operand1 Operand2
1
4
2
4
8
0
8/2
8%2
Presented by Nuzhat Memon
If the conditional ternary is
next = (N%2==0)?(N/2):(3*N+1); where N=7 then what will be the value
of variable next?
(A) 22 (B) 7 (C) 3.5 (D) 0
5
3*N+1
N%2==0
N/2
true false
N=7
7%2==0
false
3*7+1 =22
Presented by Nuzhat Memon
While using shorthand version of assignment, it is defined as a+=b where a
is 7 and b is 8 then what will result of a ?
(A) 8 (B) 49 (C) 14 (D) 15
6
<variable>=<variable><operator><expression> <variable><operator> = <expression>;
a=a+b a+=b
a=a-b a-=b
a=a*b a*=b
a=a/b a/=b
a+=b
a=a + b
=7+ 8
Presented by Nuzhat Memon
Thanks!
Any questions?
You can find me at:
+ nuzhatmemon.com
+ nuzhat.memon@gmail.com
7
Presented by Nuzhat Memon 8
Branches/decision/selective
Control Structures
Do while loop
Looping
For loop While loop
If statement Switch case
In general, the statements are executed sequentially, one by one. Sometimes,
program logic needs to change the flow of this sequence.
The statements that enable to control the flow of execution are considered as
control structures
Control Structures
Presented by Nuzhat Memon 9
Entry controlled or pre-test
loop constructs.
It is used when numbers of
iterations are pre-defined.
Entry controlled or pre-test
loop constructs.
It is used when number of
iterations are not
pre-determined.
Exit controlled or post-test
loop constructs.
Here, statements of loop are
executed at least once.
Do while loop
Looping
For loop While loop
for (initialize; condition; iteration){
statements;
}
//initialize
while (condition){
statements;
increment/decrement statement;
}
//initialize
Do{
statements;
increment/decr statement;
} while (condition);
 Loops are used to repeat a sequence of statements over and over until some condition occurs.
 Loop are executed if condition is true.
 Java supports 3 types of looping constructs:
Looping
Presented by Nuzhat Memon
Brain Stroming Session
Which of the following is compiled error free?
(A)for(;;){int i=7}; (B) while (1) { int i=7};
(C) while (true){int i=7} (D) All of these
What will be output of following program?
class abc{
public static void main(string[] S){
for(int i=0;i<10;i++){
SYSTEM.out.println(i);
}
}
}
(A) error (B) i (C) Display 1 to 10 (D) 1,2,3,…….10
10
Presented by Nuzhat Memon
Statement (selective structure)
Control structure branches are used to choose among two or
more possible courses of action, is called as selective structure
(1) IF STATEMENT
+ Used in a program to take one of two alternative coursed of
action, depending upon Boolean valued expression.
(2) SWITCH STATEMENT
+ Used when there are many alternative actions to be taken
depending upon the value of a variable or expression.
+ Test expression should be of the type byte, char, short or int
or enum
11
if(condition){
statements;
}
Else{
statements;
}
Switch (option){
case 1:
statement1;
break;
case 2:
statement2;
break;
default:
statementN;
}
Presented by Nuzhat Memon 12
Entry controlled or pre-test
loop constructs.
It is used when numbers of
iterations are pre-defined.
Entry controlled or pre-test
loop constructs.
It is used when number of
iterations are not
pre-determined.
Exit controlled or post-test
loop constructs.
Here, statements of loop are
executed at least once.
Do while loop
Looping
For loop While loop
for (initialize; condition; iteration){
statements;
}
//initialize
while (condition){
statements;
increment/decrement statement;
}
//initialize
Do{
statements;
increment/decr statement;
} while (condition);
Control structure branches are used to choose among two or more possible
courses of action, is called as selective structure
statement
Presented by Nuzhat Memon
Which statement is executed if the value of Boolean expression is true?
If (boolean expression)
{
<statement1>
}
else
{
<statement2>
}
(A) statement2 (B) error message (C) statement1 (D) statement3
13
Presented by Nuzhat Memon
Statement
BREAK STATEMENT
+ Used to transfer the control outside switch/loop
structure.
+ It is used to exit the loop.
+ It is jumps outside the nearest loop containing
this statement.
CONTINUE STATEMENT
+ It is used to skip the following statement in a loop
and continue with the next iteration.
14
for(){
if(condition){
break;
}
statements;
}
for(){
if(condition){
continue;
}
statements;
}

More Related Content

PPTX
Std 12 computer java basics part 3 control structure
PPTX
Python decision making_loops part7
PPT
Control structures ii
PDF
Java conditional statements
PPTX
Flow of control by deepak lakhlan
PPT
Java control flow statements
PPT
Control structures i
PPT
Repetition Structure
Std 12 computer java basics part 3 control structure
Python decision making_loops part7
Control structures ii
Java conditional statements
Flow of control by deepak lakhlan
Java control flow statements
Control structures i
Repetition Structure

What's hot (20)

PDF
(chapter 2) A Concise and Practical Introduction to Programming Algorithms in...
PPT
Control Structures: Part 1
PPTX
Control statement-Selective
PPTX
Control statements in java
PPTX
07 flow control
PPTX
Operators used in vb.net
PDF
Control structures in Java
PPTX
Control structures in java
PPT
The Three Basic Selection Structures in C++ Programming Concepts
PPT
Control structure C++
PPTX
Java Decision Control
PPT
Control Structure in C
PDF
Loops and conditional statements
PPTX
Switch statement, break statement, go to statement
PPTX
Java essence part 1
PPTX
Looping statements
PPTX
Program control statements in c#
PPT
Control statements in java programmng
PPT
Behavioral modeling
(chapter 2) A Concise and Practical Introduction to Programming Algorithms in...
Control Structures: Part 1
Control statement-Selective
Control statements in java
07 flow control
Operators used in vb.net
Control structures in Java
Control structures in java
The Three Basic Selection Structures in C++ Programming Concepts
Control structure C++
Java Decision Control
Control Structure in C
Loops and conditional statements
Switch statement, break statement, go to statement
Java essence part 1
Looping statements
Program control statements in c#
Control statements in java programmng
Behavioral modeling
Ad

Similar to Std 12 Computer Chapter 7 Java Basics (Part 2) (20)

PPTX
Module2.2_Operators-in-C-Programming.pptx
DOC
C fundamental
PPT
Control statments in c
PPTX
Class_IX_Operators.pptx
PPT
C operators
PPTX
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
PPTX
Java PSkills Session-3 PNR.pptx
PDF
SPIN Cours SPIN Cours SPIN Cours SPIN Cours
PDF
introduction to c programming - Topic 3.pdf
PPTX
UNIT 2 programming in java_operators.pptx
PDF
AI Lesson 39
PDF
Lesson 39
PPTX
control statements
PDF
[C++][a] tutorial 2
PPTX
Control statements in c
PPTX
Java covers syntax, data types, object-oriented concepts, control flow, excep...
PPT
Chap05
PDF
Programming for Problem Solving
PPT
Loops_and_FunctionsWeek4_0.ppt
Module2.2_Operators-in-C-Programming.pptx
C fundamental
Control statments in c
Class_IX_Operators.pptx
C operators
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Java PSkills Session-3 PNR.pptx
SPIN Cours SPIN Cours SPIN Cours SPIN Cours
introduction to c programming - Topic 3.pdf
UNIT 2 programming in java_operators.pptx
AI Lesson 39
Lesson 39
control statements
[C++][a] tutorial 2
Control statements in c
Java covers syntax, data types, object-oriented concepts, control flow, excep...
Chap05
Programming for Problem Solving
Loops_and_FunctionsWeek4_0.ppt
Ad

More from Nuzhat Memon (20)

PPTX
Std 10 chapter 11 data type, expression and operators important MCQs
PPTX
Std 10 Chapter 10 Introduction to C Language Important MCQs
PPTX
Std 12 chapter 7 Java Basics Important MCQs
PPTX
Std 12 computer chapter 8 classes and objects in java important MCQs
PPTX
Std 12 Computer Chapter 6 object oriented concept important mcqs
PPTX
Std 12 computer chapter 6 object oriented concepts (part 1)
PPTX
Std 12 computer chapter 6 object oriented concepts (part 2)
PPTX
Std 12 Computer Chapter 7 Java Basics (Part 1)
PPTX
Std 12 Computer Chapter 13 other useful free tools and services important MCQs
PPTX
Std 12 Computer Chapter 9 Working with Array and String in Java important MCQs
PPTX
Std 12 computer chapter 8 classes and object in java (part 2)
PPTX
Std 10 computer chapter 10 introduction to c language (part2)
PPTX
Std 10 computer chapter 10 introduction to c language (part1)
PPTX
Std 10 computer chapter 9 Problems and Problem Solving
PPTX
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 3: Masking to R...
PPTX
Chapter 5 Using Pictures in Synfig (Practical 2: Masking to hide area in synfig)
PPTX
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 1 Basics Opera...
PPTX
Std 11 Computer Chapter 4 Introduction to Layers (Part 3 Solving Textual Exe...
PPTX
Std 11 Computer Chapter 4 Introduction to Layers (Part 2 Practical :Rotation ...
PPTX
Std 11 Computer Chapter 4 Introduction to Layers
Std 10 chapter 11 data type, expression and operators important MCQs
Std 10 Chapter 10 Introduction to C Language Important MCQs
Std 12 chapter 7 Java Basics Important MCQs
Std 12 computer chapter 8 classes and objects in java important MCQs
Std 12 Computer Chapter 6 object oriented concept important mcqs
Std 12 computer chapter 6 object oriented concepts (part 1)
Std 12 computer chapter 6 object oriented concepts (part 2)
Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 13 other useful free tools and services important MCQs
Std 12 Computer Chapter 9 Working with Array and String in Java important MCQs
Std 12 computer chapter 8 classes and object in java (part 2)
Std 10 computer chapter 10 introduction to c language (part2)
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 9 Problems and Problem Solving
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 3: Masking to R...
Chapter 5 Using Pictures in Synfig (Practical 2: Masking to hide area in synfig)
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 1 Basics Opera...
Std 11 Computer Chapter 4 Introduction to Layers (Part 3 Solving Textual Exe...
Std 11 Computer Chapter 4 Introduction to Layers (Part 2 Practical :Rotation ...
Std 11 Computer Chapter 4 Introduction to Layers

Recently uploaded (20)

PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Pre independence Education in Inndia.pdf
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
From loneliness to social connection charting
PDF
Open folder Downloads.pdf yes yes ges yes
PDF
Anesthesia in Laparoscopic Surgery in India
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Pre independence Education in Inndia.pdf
Cardiovascular Pharmacology for pharmacy students.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
Week 4 Term 3 Study Techniques revisited.pptx
Open Quiz Monsoon Mind Game Final Set.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
How to Manage Starshipit in Odoo 18 - Odoo Slides
Abdominal Access Techniques with Prof. Dr. R K Mishra
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
From loneliness to social connection charting
Open folder Downloads.pdf yes yes ges yes
Anesthesia in Laparoscopic Surgery in India

Std 12 Computer Chapter 7 Java Basics (Part 2)

  • 1. Chapter 7 Java Basics (Part 2 – Operators in java) Presented by nuzhat memon Operat ors 1. Arithme tic Operato rs 2. Compari son operato rs 3. Logical Operato rs 4. Conditio nal operato rs 5. Assignm ent operato r
  • 2. Chapter 7 Java Basics (Part 2 – Operators in java) Presented by nuzhat memon Operator s 1. Arithmetic Operators 2. Comparison operators 3. Logical Operators 4. Conditional operators 5. Assignment operator
  • 3. Presented by Nuzhat Memon Operators + Operators are special symbols used to build an expression. 3 Operators 1. Arithmetic Operators 2. Comparison operators 3. Logical Operators 4. Conditional operators 5. Assignment operator
  • 4. Presented by Nuzhat Memon 4 Basic arithmetic operators are +, – , *, / , % (Modulus) All these operators are binary, they take 2 operands. Used for byte, short, int, long, float, double and char (treated as int) Arithmetic Operators Operator Meaning Eg + Addition 2+8 – Subtraction 2-8 * Multiplication 2*8 / Division 8/2 % Reminder 8%3 ++ & -- is known as unary operators ++ is increment operator (which adds 1) and -- is decrement operator (which subtracts 1) Increment / Decrement Operators ++x pre-increment --x pre-decrement x++ post -increment x-- post-decrement Comparison operators are known as relational operators. The result of expression is boolean; either true or false Comparison Operators Operator Meaning > Greater than < Less than >= Greater than or equal to <= Less than or equal to == Equal to != Not equal to Logical operators known as boolean operators. Logical operators: AND, OR, XOR (Exclusive OR), NOT Logical Operators Operator Sign Use AND && Used to combine two values OR || Used to combine two values XOR ^ It returns true only if operands are different NOT ! Operant is true, result is false & vice versa Also known as ternary operator. Conditional operator uses 3 operands. It uses two symbols ? and : in the expression. Syntax : (boolean-expr) ? (expr1) : (expr2) To assign a value to variable by using the assignment operator ‘=’ Syntax: <variable> = <expression>; Variable on lefthand side of expression is lvalue (location in memory) Conditional Operator Operators Arithmetic Operator Increment and Decrement Operator Comparison Operator Logical Operator Assignment Operator Operator Operand1 Operand2 1 4 2 4 8 0 8/2 8%2
  • 5. Presented by Nuzhat Memon If the conditional ternary is next = (N%2==0)?(N/2):(3*N+1); where N=7 then what will be the value of variable next? (A) 22 (B) 7 (C) 3.5 (D) 0 5 3*N+1 N%2==0 N/2 true false N=7 7%2==0 false 3*7+1 =22
  • 6. Presented by Nuzhat Memon While using shorthand version of assignment, it is defined as a+=b where a is 7 and b is 8 then what will result of a ? (A) 8 (B) 49 (C) 14 (D) 15 6 <variable>=<variable><operator><expression> <variable><operator> = <expression>; a=a+b a+=b a=a-b a-=b a=a*b a*=b a=a/b a/=b a+=b a=a + b =7+ 8
  • 7. Presented by Nuzhat Memon Thanks! Any questions? You can find me at: + nuzhatmemon.com + [email protected] 7
  • 8. Presented by Nuzhat Memon 8 Branches/decision/selective Control Structures Do while loop Looping For loop While loop If statement Switch case In general, the statements are executed sequentially, one by one. Sometimes, program logic needs to change the flow of this sequence. The statements that enable to control the flow of execution are considered as control structures Control Structures
  • 9. Presented by Nuzhat Memon 9 Entry controlled or pre-test loop constructs. It is used when numbers of iterations are pre-defined. Entry controlled or pre-test loop constructs. It is used when number of iterations are not pre-determined. Exit controlled or post-test loop constructs. Here, statements of loop are executed at least once. Do while loop Looping For loop While loop for (initialize; condition; iteration){ statements; } //initialize while (condition){ statements; increment/decrement statement; } //initialize Do{ statements; increment/decr statement; } while (condition);  Loops are used to repeat a sequence of statements over and over until some condition occurs.  Loop are executed if condition is true.  Java supports 3 types of looping constructs: Looping
  • 10. Presented by Nuzhat Memon Brain Stroming Session Which of the following is compiled error free? (A)for(;;){int i=7}; (B) while (1) { int i=7}; (C) while (true){int i=7} (D) All of these What will be output of following program? class abc{ public static void main(string[] S){ for(int i=0;i<10;i++){ SYSTEM.out.println(i); } } } (A) error (B) i (C) Display 1 to 10 (D) 1,2,3,…….10 10
  • 11. Presented by Nuzhat Memon Statement (selective structure) Control structure branches are used to choose among two or more possible courses of action, is called as selective structure (1) IF STATEMENT + Used in a program to take one of two alternative coursed of action, depending upon Boolean valued expression. (2) SWITCH STATEMENT + Used when there are many alternative actions to be taken depending upon the value of a variable or expression. + Test expression should be of the type byte, char, short or int or enum 11 if(condition){ statements; } Else{ statements; } Switch (option){ case 1: statement1; break; case 2: statement2; break; default: statementN; }
  • 12. Presented by Nuzhat Memon 12 Entry controlled or pre-test loop constructs. It is used when numbers of iterations are pre-defined. Entry controlled or pre-test loop constructs. It is used when number of iterations are not pre-determined. Exit controlled or post-test loop constructs. Here, statements of loop are executed at least once. Do while loop Looping For loop While loop for (initialize; condition; iteration){ statements; } //initialize while (condition){ statements; increment/decrement statement; } //initialize Do{ statements; increment/decr statement; } while (condition); Control structure branches are used to choose among two or more possible courses of action, is called as selective structure statement
  • 13. Presented by Nuzhat Memon Which statement is executed if the value of Boolean expression is true? If (boolean expression) { <statement1> } else { <statement2> } (A) statement2 (B) error message (C) statement1 (D) statement3 13
  • 14. Presented by Nuzhat Memon Statement BREAK STATEMENT + Used to transfer the control outside switch/loop structure. + It is used to exit the loop. + It is jumps outside the nearest loop containing this statement. CONTINUE STATEMENT + It is used to skip the following statement in a loop and continue with the next iteration. 14 for(){ if(condition){ break; } statements; } for(){ if(condition){ continue; } statements; }