SlideShare a Scribd company logo
1 of 9
Decision Making in Java
•if statement
•else if statement
•If else if statement
•Nested if statements
•Switch Statement
4/10/2019 1Jamsher Bhanbhro(F16CS11)
Decision Making
• In decision making there are one or more
conditions to be checked during the execution
of a program.
• The decision depends upon our conditions as
it may return true or false result.
4/10/2019 Jamsher Bhanbhro(F16CS11) 2
If statement
If statement is used to check one or more
Boolean conditions to execute a block of
statements or code.
• Syntax: if(Boolean Statements){//code body to
be executed if the statement is true}
E.g: if(a>11){
System.out.println(“Your
Condition is true”);}
4/10/2019 Jamsher Bhanbhro(F16CS11) 3
If else statement
• An if statement can be followed by the else statement if
statement will be executed when your condition is true
and in the case of the else statement it will be executed
when if’s condition will be false.
• I.E:
int a=3;
if(a>2){
System.out.println(“If is true”);}
else{
System.out.println(“If is false”);}
4/10/2019 Jamsher Bhanbhro(F16CS11) 4
If else if statement
• An if statement is followed by an optional else if
statement.
• One else if statement is correct than all followed
statements will not be executed.
• If(Bool Cond){}else if(cond){}else
if(cond){}……
int a=11;
If(a<11){}
else if(a<9){}…
4/10/2019 Jamsher Bhanbhro(F16CS11) 5
Nested If
• It means we can use if or else if inside the if
statement.
• Than all conditions will be executed
sequentially.
• If(Bool Cond){if(bool cond){}}….
4/10/2019 Jamsher Bhanbhro(F16CS11) 6
Switch Statement
• A value to be sated in a variable.
• And on that value conditions will be checked accordingly.
• Each value is called case, variables can be integer type, char
type or Boolean type.
• Understand syntax of the Switch statement in the following
program
I.E: int a;
Switch(a){
case ‘1’: System.out.println(“Jamsher”);}
break;
case’2’: ….}
4/10/2019 Jamsher Bhanbhro(F16CS11) 7
Why Decision making is used in
programming?
4/10/2019 Jamsher Bhanbhro(F16CS11) 8
4/10/2019 Jamsher Bhanbhro(F16CS11) 9

More Related Content

Similar to Lect8

Week03
Week03Week03
Week03
hccit
 

Similar to Lect8 (20)

python conditional statement.pptx
python conditional statement.pptxpython conditional statement.pptx
python conditional statement.pptx
 
Week03
Week03Week03
Week03
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 
Conditional statements & Loops
Conditional statements & LoopsConditional statements & Loops
Conditional statements & Loops
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Decision control structures
Decision control structuresDecision control structures
Decision control structures
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
What are conditional statements?
What are conditional statements?What are conditional statements?
What are conditional statements?
 
Flow of execution.pptx
Flow of execution.pptxFlow of execution.pptx
Flow of execution.pptx
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
If statements in C
If statements in CIf statements in C
If statements in C
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structures
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Decision statements
Decision statementsDecision statements
Decision statements
 
Control statements
Control statementsControl statements
Control statements
 

More from Jamsher bhanbhro

More from Jamsher bhanbhro (14)

Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and Interfaces
 
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In  JavaMethod, Constructor, Method Overloading, Method Overriding, Inheritance In  Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
 
Regular Expressions in Java.
Regular Expressions in Java.Regular Expressions in Java.
Regular Expressions in Java.
 
Java Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJava Arrays and DateTime Functions
Java Arrays and DateTime Functions
 
Lect10
Lect10Lect10
Lect10
 
Lect9
Lect9Lect9
Lect9
 
Lect7
Lect7Lect7
Lect7
 
Lect6
Lect6Lect6
Lect6
 
Lect5
Lect5Lect5
Lect5
 
Lect4
Lect4Lect4
Lect4
 
Compiling and understanding first program in java
Compiling and understanding first program in javaCompiling and understanding first program in java
Compiling and understanding first program in java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Caap presentation by me
Caap presentation by meCaap presentation by me
Caap presentation by me
 
Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)
 

Recently uploaded

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 

Lect8

  • 1. Decision Making in Java •if statement •else if statement •If else if statement •Nested if statements •Switch Statement 4/10/2019 1Jamsher Bhanbhro(F16CS11)
  • 2. Decision Making • In decision making there are one or more conditions to be checked during the execution of a program. • The decision depends upon our conditions as it may return true or false result. 4/10/2019 Jamsher Bhanbhro(F16CS11) 2
  • 3. If statement If statement is used to check one or more Boolean conditions to execute a block of statements or code. • Syntax: if(Boolean Statements){//code body to be executed if the statement is true} E.g: if(a>11){ System.out.println(“Your Condition is true”);} 4/10/2019 Jamsher Bhanbhro(F16CS11) 3
  • 4. If else statement • An if statement can be followed by the else statement if statement will be executed when your condition is true and in the case of the else statement it will be executed when if’s condition will be false. • I.E: int a=3; if(a>2){ System.out.println(“If is true”);} else{ System.out.println(“If is false”);} 4/10/2019 Jamsher Bhanbhro(F16CS11) 4
  • 5. If else if statement • An if statement is followed by an optional else if statement. • One else if statement is correct than all followed statements will not be executed. • If(Bool Cond){}else if(cond){}else if(cond){}…… int a=11; If(a<11){} else if(a<9){}… 4/10/2019 Jamsher Bhanbhro(F16CS11) 5
  • 6. Nested If • It means we can use if or else if inside the if statement. • Than all conditions will be executed sequentially. • If(Bool Cond){if(bool cond){}}…. 4/10/2019 Jamsher Bhanbhro(F16CS11) 6
  • 7. Switch Statement • A value to be sated in a variable. • And on that value conditions will be checked accordingly. • Each value is called case, variables can be integer type, char type or Boolean type. • Understand syntax of the Switch statement in the following program I.E: int a; Switch(a){ case ‘1’: System.out.println(“Jamsher”);} break; case’2’: ….} 4/10/2019 Jamsher Bhanbhro(F16CS11) 7
  • 8. Why Decision making is used in programming? 4/10/2019 Jamsher Bhanbhro(F16CS11) 8