SlideShare a Scribd company logo
1 of 12
IMPLEMENTING MULTIPLE
SELECTIONS
Chapter 4.4:
Multiple Selection (nested if)
 Syntax:
if (expression1)
statement1
else
if (expression2)
statement2
else
statement3
Java code (multiple
selection)
if (a>=1)
{
System.out.println ("The number you enter is :" + a);
System.out.println ("You enter the positive number");
}
else if (a<0)
{
System.out.println ("The number you enter is :" + a);
System.out.println ("You enter the negative number");
}
else
{
System.out.println ("The number you enter is :" + a);
System.out.println ("You enter the zero number");
}
Output
Enter the number : 15
The number you enter is :15
You enter the positive number
Enter the number : -15
The number you enter is :-15
You enter the negative number
Enter the number : 0
The number you enter is :0
You enter the zero number
Multiple Selections
Example
 The grading scheme for a course is given as
below:
Mark Grade
90 - 100 A
80 – 89 B
70 – 79 C
60 – 69 D
0 - 59 F
Read a mark & determine the grade.
Multiple Selections
if (mark >= 90)
grade = ‘A’;
else if (mark >= 80)
grade = ‘B’;
else if (mark >= 70)
grade = ‘C’;
else if (mark >= 60)
grade = ‘D’;
else
grade = ‘F’;
Equivalent code with series of if
statements
if ((mark >= 90) && (mark <=100))
grade = ‘A’;
if ((mark >= 80) && (mark >= 89))
grade = ‘B’;
if ((mark >= 70) && (mark >= 79))
grade = ‘C’;
if ((mark >= 60) && (mark >= 69))
grade = ‘D’;
if ((mark >= 0) && (mark >= 59))
grade = ‘F’;
switch Structures (multiple
selection)
 Expression is
also known as
selector.
 Value can only
be integral.
switch (expression)
{
case value1: statements1
break;
case value2: statements2
break;
...
case valuen: statementsn
break;
default: statements
}
If expression
matches value2,
control jumps
to here
switch Structures
The switch Statement
 Often a break statement is used as the last
statement in each case's statement list
 A break statement causes control to transfer to
the end of the switch statement
 If a break statement is not used, the flow of
control will continue into the next case
Control flow of switch statement
with and without the break
statements
Switch/Break Examples
int m = 2;
switch (m)
{
case 1 :
System.out.println(“m=1”);
break;
case 2 :
System.out.println(“m=2”);
break;
case 3 :
System.out.println(“m=3”);
break;
default:
System.out.println(“default”);}
Output: m=2
char ch = ‘b’;
switch (ch)
{
case ‘a’ :
System.out.println(“ch=a”);
case ‘b’ :
System.out.println(“ch=b”);
case ‘c’ :
System.out.println(“ch=c”);
default:
System.out.println(“default”);
}
Output: ch=b
ch=c
default

More Related Content

What's hot

C++ control structure
C++ control structureC++ control structure
C++ control structure
bluejayjunior
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
eShikshak
 

What's hot (20)

Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 
Decision Control Structure If & Else
Decision Control Structure If & ElseDecision Control Structure If & Else
Decision Control Structure If & Else
 
Unit 5. Control Statement
Unit 5. Control StatementUnit 5. Control Statement
Unit 5. Control Statement
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Ch3 selection
Ch3 selectionCh3 selection
Ch3 selection
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
130706266060138191
130706266060138191130706266060138191
130706266060138191
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 

Viewers also liked (10)

Rhino 3D Εξ Αποστάσεως
Rhino 3D Εξ ΑποστάσεωςRhino 3D Εξ Αποστάσεως
Rhino 3D Εξ Αποστάσεως
 
Chapter 6.4
Chapter 6.4Chapter 6.4
Chapter 6.4
 
Rhino 3D
Rhino 3DRhino 3D
Rhino 3D
 
Rhino 3D Primer
Rhino 3D PrimerRhino 3D Primer
Rhino 3D Primer
 
Grasshopper Generative Modelling + Rhino
Grasshopper Generative Modelling + RhinoGrasshopper Generative Modelling + Rhino
Grasshopper Generative Modelling + Rhino
 
Easy Steps to Better Maps
Easy Steps to Better MapsEasy Steps to Better Maps
Easy Steps to Better Maps
 
DUSPviz Rhino 3D Workshop
DUSPviz Rhino 3D WorkshopDUSPviz Rhino 3D Workshop
DUSPviz Rhino 3D Workshop
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual Basic
 
Parametric Architecture Talk (Presented 13 March 2013)
Parametric Architecture Talk (Presented 13 March 2013)Parametric Architecture Talk (Presented 13 March 2013)
Parametric Architecture Talk (Presented 13 March 2013)
 
Control statements
Control statementsControl statements
Control statements
 

Similar to Chapter 4.4

Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control Structures
PRN USM
 
Chap7_b Control Statement Looping (3).pptx
Chap7_b Control Statement Looping (3).pptxChap7_b Control Statement Looping (3).pptx
Chap7_b Control Statement Looping (3).pptx
FakhriyArif
 
Cs1123 5 selection_if
Cs1123 5 selection_ifCs1123 5 selection_if
Cs1123 5 selection_if
TAlha MAlik
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
Sanjjaayyy
 

Similar to Chapter 4.4 (20)

Chapter 1 Nested Control Structures
Chapter 1 Nested Control StructuresChapter 1 Nested Control Structures
Chapter 1 Nested Control Structures
 
Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control Structures
 
Chapter 1 nested control structures
Chapter 1 nested control structuresChapter 1 nested control structures
Chapter 1 nested control structures
 
unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
3. control statements
3. control statements3. control statements
3. control statements
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
C Unit-2.ppt
C Unit-2.pptC Unit-2.ppt
C Unit-2.ppt
 
C# Control Statements, For loop, Do While.ppt
C# Control Statements, For loop, Do While.pptC# Control Statements, For loop, Do While.ppt
C# Control Statements, For loop, Do While.ppt
 
Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Visula C# Programming Lecture 3
Visula C# Programming Lecture 3
 
Control All
Control AllControl All
Control All
 
Comp102 lec 5.1
Comp102   lec 5.1Comp102   lec 5.1
Comp102 lec 5.1
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
CONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxCONTROL FLOW in C.pptx
CONTROL FLOW in C.pptx
 
Chap7_b Control Statement Looping (3).pptx
Chap7_b Control Statement Looping (3).pptxChap7_b Control Statement Looping (3).pptx
Chap7_b Control Statement Looping (3).pptx
 
C programming
C programmingC programming
C programming
 
3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf3-Conditional-if-else-switch btech computer in c.pdf
3-Conditional-if-else-switch btech computer in c.pdf
 
Cs1123 5 selection_if
Cs1123 5 selection_ifCs1123 5 selection_if
Cs1123 5 selection_if
 
CONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.pptCONTROLSTRUCTURES.ppt
CONTROLSTRUCTURES.ppt
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
 

More from sotlsoc

Chapter 2.0 new
Chapter 2.0 newChapter 2.0 new
Chapter 2.0 new
sotlsoc
 
Chapter 1.0 new
Chapter 1.0 newChapter 1.0 new
Chapter 1.0 new
sotlsoc
 
Chapter 3.0 new
Chapter 3.0 newChapter 3.0 new
Chapter 3.0 new
sotlsoc
 
Chapter 6.5 new
Chapter 6.5 newChapter 6.5 new
Chapter 6.5 new
sotlsoc
 
Chapter 11.1
Chapter 11.1Chapter 11.1
Chapter 11.1
sotlsoc
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
sotlsoc
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4
sotlsoc
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3
sotlsoc
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
sotlsoc
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2
sotlsoc
 
Chapter 11.0
Chapter 11.0Chapter 11.0
Chapter 11.0
sotlsoc
 
Chapter 10.2
Chapter 10.2Chapter 10.2
Chapter 10.2
sotlsoc
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
sotlsoc
 
Chapter 8.0
Chapter 8.0Chapter 8.0
Chapter 8.0
sotlsoc
 
Chapter 10.0
Chapter 10.0Chapter 10.0
Chapter 10.0
sotlsoc
 
Chapter 9.3
Chapter 9.3Chapter 9.3
Chapter 9.3
sotlsoc
 
Chapter 9.4
Chapter 9.4Chapter 9.4
Chapter 9.4
sotlsoc
 
Chapter 9.1
Chapter 9.1Chapter 9.1
Chapter 9.1
sotlsoc
 
Chapter 8.1
Chapter 8.1Chapter 8.1
Chapter 8.1
sotlsoc
 
Chapter 9.0
Chapter 9.0Chapter 9.0
Chapter 9.0
sotlsoc
 

More from sotlsoc (20)

Chapter 2.0 new
Chapter 2.0 newChapter 2.0 new
Chapter 2.0 new
 
Chapter 1.0 new
Chapter 1.0 newChapter 1.0 new
Chapter 1.0 new
 
Chapter 3.0 new
Chapter 3.0 newChapter 3.0 new
Chapter 3.0 new
 
Chapter 6.5 new
Chapter 6.5 newChapter 6.5 new
Chapter 6.5 new
 
Chapter 11.1
Chapter 11.1Chapter 11.1
Chapter 11.1
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2
 
Chapter 11.0
Chapter 11.0Chapter 11.0
Chapter 11.0
 
Chapter 10.2
Chapter 10.2Chapter 10.2
Chapter 10.2
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
 
Chapter 8.0
Chapter 8.0Chapter 8.0
Chapter 8.0
 
Chapter 10.0
Chapter 10.0Chapter 10.0
Chapter 10.0
 
Chapter 9.3
Chapter 9.3Chapter 9.3
Chapter 9.3
 
Chapter 9.4
Chapter 9.4Chapter 9.4
Chapter 9.4
 
Chapter 9.1
Chapter 9.1Chapter 9.1
Chapter 9.1
 
Chapter 8.1
Chapter 8.1Chapter 8.1
Chapter 8.1
 
Chapter 9.0
Chapter 9.0Chapter 9.0
Chapter 9.0
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 

Recently uploaded (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

Chapter 4.4

  • 2. Multiple Selection (nested if)  Syntax: if (expression1) statement1 else if (expression2) statement2 else statement3
  • 3. Java code (multiple selection) if (a>=1) { System.out.println ("The number you enter is :" + a); System.out.println ("You enter the positive number"); } else if (a<0) { System.out.println ("The number you enter is :" + a); System.out.println ("You enter the negative number"); } else { System.out.println ("The number you enter is :" + a); System.out.println ("You enter the zero number"); }
  • 4. Output Enter the number : 15 The number you enter is :15 You enter the positive number Enter the number : -15 The number you enter is :-15 You enter the negative number Enter the number : 0 The number you enter is :0 You enter the zero number
  • 5. Multiple Selections Example  The grading scheme for a course is given as below: Mark Grade 90 - 100 A 80 – 89 B 70 – 79 C 60 – 69 D 0 - 59 F Read a mark & determine the grade.
  • 6. Multiple Selections if (mark >= 90) grade = ‘A’; else if (mark >= 80) grade = ‘B’; else if (mark >= 70) grade = ‘C’; else if (mark >= 60) grade = ‘D’; else grade = ‘F’;
  • 7. Equivalent code with series of if statements if ((mark >= 90) && (mark <=100)) grade = ‘A’; if ((mark >= 80) && (mark >= 89)) grade = ‘B’; if ((mark >= 70) && (mark >= 79)) grade = ‘C’; if ((mark >= 60) && (mark >= 69)) grade = ‘D’; if ((mark >= 0) && (mark >= 59)) grade = ‘F’;
  • 8. switch Structures (multiple selection)  Expression is also known as selector.  Value can only be integral. switch (expression) { case value1: statements1 break; case value2: statements2 break; ... case valuen: statementsn break; default: statements } If expression matches value2, control jumps to here
  • 10. The switch Statement  Often a break statement is used as the last statement in each case's statement list  A break statement causes control to transfer to the end of the switch statement  If a break statement is not used, the flow of control will continue into the next case
  • 11. Control flow of switch statement with and without the break statements
  • 12. Switch/Break Examples int m = 2; switch (m) { case 1 : System.out.println(“m=1”); break; case 2 : System.out.println(“m=2”); break; case 3 : System.out.println(“m=3”); break; default: System.out.println(“default”);} Output: m=2 char ch = ‘b’; switch (ch) { case ‘a’ : System.out.println(“ch=a”); case ‘b’ : System.out.println(“ch=b”); case ‘c’ : System.out.println(“ch=c”); default: System.out.println(“default”); } Output: ch=b ch=c default