SlideShare a Scribd company logo
1 of 20
Using Java
MINISTRY OF EDUCATION & HIGHER EDUCATION
COLLEGE OF SCIENCE AND TECHNOLOGY
KHANYOUNIS- PALESTINE
Lecture 7
Decision Making : selection statements (cont.)
 if...else Double-Selection Statement
 Nested if...else Statements
 Blocks
 Switch
 Be care
 Practices
 Emank X Mezank
2Presented & Prepared by: Mahmoud R. Alfarra
 The if...else double-selection statement
allows the programmer to specify an action
to perform when the condition is true and a
different action when the condition is false.
3Presented & Prepared by: Mahmoud R. Alfarra
if...else Double-Selection Statement
If student's grade is greater than or equal to 60
Print "Passed"
Else
Print "Failed"
if ( grade >= 60 )
System.out.println( "Passed" );
else
System.out.println( "Failed" );
4Presented & Prepared by: Mahmoud R. Alfarra
if...else Double-Selection Statement
X<=0
yes
F(x)= XF(x)= - X
NO
Write a program to code the above flowchart
HW 7.1
 Write a program to receive an integer from
user and then print if it is an even or an odd
5Presented & Prepared by: Mahmoud R. Alfarra
Example: Print Even or Odd
Write the pseudo code and flowchart of the above
exampleHW 7.2
6Presented & Prepared by: Mahmoud R. Alfarra
Example: Print Even or Odd
Write a program to receive two an integer from
user and then print if it is an even or an oddHW 7.3
If student's grade is greater than or equal to 90
Print "A"
else If student's grade is greater than or equal to 80
Print "B"
else If student's grade is greater than or equal to 70
Print "C"
else If student's grade is greater than or equal to 60
Print "D"
else
Print "F"
 A program can test multiple cases by placing
if...else statements inside other if...else
statements to create nested if...else
statements.
7Presented & Prepared by: Mahmoud R. Alfarra
Nested if...else Statements
8Presented & Prepared by: Mahmoud R. Alfarra
if...else Double-Selection Statement
X<=50
yes
return “Success”
return fail
NO
X<=80
yesNO
return “pass”
 Write a program to receive the user name
and then password from user, and if the user
name matches “onway2allah” and the
password matches “muslim4ever”, the
program print “open”.
 Else the program print “pass is mismatched”
or & “user is mismatched”.
9Presented & Prepared by: Mahmoud R. Alfarra
Example: Privacy login
Write the pseudo code and flowchart of the above
exampleHW 7.4
10Presented & Prepared by: Mahmoud R. Alfarra
Write a program to receive two an integer from
user and then print if it is an even or an oddHW 7.5
Example: Privacy login
11Presented & Prepared by: Mahmoud R. Alfarra
Comparing strings : Be care
Comparing strings is doing by using (ComparTo) method, not
by == .
Using the following formula:
String1.ComparTo(string2) , this comparison results:
• 1 : means the string1 is larger than string2
• -1: means the string2 is larger than string1
• 0: means the two strings are equal
Using the following formula:
“Ali”.ComparTo(“zain”) = 1
“Ali”.ComparTo(“Ali”) = 0
“yahia”.ComparTo(“ahmad”) = -1
 The if statement normally expects only one
statement in its body.
 To include several statements in the body of
an if (or the body of an else), enclose the
statements in braces ({ and }).
 A set of statements contained within a pair of
braces is called a block.
12Presented & Prepared by: Mahmoud R. Alfarra
Blocks
 A block can be placed anywhere in a program
that a single statement can be placed.
13Presented & Prepared by: Mahmoud R. Alfarra
Blocks
Forgetting both of the braces that delimit a block will lead to
logic error in a program.
Forgetting one of the braces that delimits a block will lead to
syntax error in a program.
14Presented & Prepared by: Mahmoud R. Alfarra
Example: Blocks
if ( grade >= 60 )
System.out.println( "Passed" );
else
{
System.out.println( "Failed" );
System.out.println( "You must take this course again." );
}
 All the instructions into the block are related
to the if and else …
 Java provides the switch multiple-selection
statement to perform different actions based
on the possible values of an integer variable
or expression.
 Each action is associated with the value of a
constant integral expression.
15Presented & Prepared by: Mahmoud R. Alfarra
Switch
A constant value in expression of type byte, short,
int or char, but not long.
16Presented & Prepared by: Mahmoud R. Alfarra
Formula: Switch
switch (expr.)
{
case x:
// instructions
break;
case y:
// instructions
break;
.
.
.
default :
// instructions
}
 Write a program to receive an integer from
user and then print the day of this number as
▪ 1 : Saturday
▪ 2 : Sunday
▪ ….
▪ ….
17Presented & Prepared by: Mahmoud R. Alfarra
Example: Print Days
Write the pseudo code and flowchart of the above
exampleHW 7.6
18Presented & Prepared by: Mahmoud R. Alfarra
Example: Print Days
Re-Write this program using one of if statements
HW 7.7
‫تعاىل‬ ‫هللا‬ ‫قال‬:
(‫املنفوش‬ ‫كالعهن‬‫اجلبال‬ ‫تكون‬ ‫يوم‬)
19Presented & Prepared by: Mahmoud R. Alfarra
Practices
20Presented & Prepared by: Mahmoud R. Alfarra

More Related Content

What's hot

Operators, control statements represented in java
Operators, control statements  represented in javaOperators, control statements  represented in java
Operators, control statements represented in javaTharuniDiddekunta
 
Exception handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaException handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaManoj_vasava
 
Chapter 3 branching v4
Chapter 3 branching v4Chapter 3 branching v4
Chapter 3 branching v4Sunarto Quek
 
Cis 355 i lab 2 of 6
Cis 355 i lab 2 of 6Cis 355 i lab 2 of 6
Cis 355 i lab 2 of 6helpido9
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6comp274
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)jakejakejake2
 
The pseudocode
The pseudocodeThe pseudocode
The pseudocodeAsha Sari
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6solutionjug4
 
Vb decision making statements
Vb decision making statementsVb decision making statements
Vb decision making statementspragya ratan
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling sharqiyem
 
Intro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileIntro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileBlue Elephant Consulting
 
Error handling and debugging
Error handling and debuggingError handling and debugging
Error handling and debuggingsalissal
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selectionHamad Odhabi
 
Oop lab assignment 01
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01Drjilesh
 

What's hot (19)

Operators, control statements represented in java
Operators, control statements  represented in javaOperators, control statements  represented in java
Operators, control statements represented in java
 
Exception handling in c++ by manoj vasava
Exception handling in c++ by manoj vasavaException handling in c++ by manoj vasava
Exception handling in c++ by manoj vasava
 
Chapter 3 branching v4
Chapter 3 branching v4Chapter 3 branching v4
Chapter 3 branching v4
 
Cis 355 i lab 2 of 6
Cis 355 i lab 2 of 6Cis 355 i lab 2 of 6
Cis 355 i lab 2 of 6
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6
 
Class 9 Lecture Notes
Class 9 Lecture NotesClass 9 Lecture Notes
Class 9 Lecture Notes
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)
 
The pseudocode
The pseudocodeThe pseudocode
The pseudocode
 
Ternary operator
Ternary operatorTernary operator
Ternary operator
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
Vb decision making statements
Vb decision making statementsVb decision making statements
Vb decision making statements
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
 
Intro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileIntro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … While
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Error handling and debugging
Error handling and debuggingError handling and debugging
Error handling and debugging
 
Debugging
DebuggingDebugging
Debugging
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selection
 
Oop lab assignment 01
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01
 
Exception handling
Exception handlingException handling
Exception handling
 

Similar to 7 programming-using-java decision-making220102011

Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrayssshhzap
 
Ch3- Java Script.pdf
Ch3- Java Script.pdfCh3- Java Script.pdf
Ch3- Java Script.pdfHASENSEID
 
C conditional mod
C conditional modC conditional mod
C conditional modAnil Sharma
 
Defencive programming
Defencive programmingDefencive programming
Defencive programmingAsha Sari
 
[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)Muhammad Hammad Waseem
 
11-ScriptsAndConditionals.ppt
11-ScriptsAndConditionals.ppt11-ScriptsAndConditionals.ppt
11-ScriptsAndConditionals.pptAnjali127411
 
Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2Mahmoud Alfarra
 
Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptBinu Paul
 
Java input Scanner
Java input Scanner Java input Scanner
Java input Scanner Huda Alameen
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction onessuser656672
 

Similar to 7 programming-using-java decision-making220102011 (20)

Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrays
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
conditional_statement.pdf
conditional_statement.pdfconditional_statement.pdf
conditional_statement.pdf
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
jhtp9_ch04.ppt
jhtp9_ch04.pptjhtp9_ch04.ppt
jhtp9_ch04.ppt
 
Ch3- Java Script.pdf
Ch3- Java Script.pdfCh3- Java Script.pdf
Ch3- Java Script.pdf
 
C conditional mod
C conditional modC conditional mod
C conditional mod
 
Defencive programming
Defencive programmingDefencive programming
Defencive programming
 
[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)[ITP - Lecture 08] Decision Control Structures (If Statement)
[ITP - Lecture 08] Decision Control Structures (If Statement)
 
11-ScriptsAndConditionals.ppt
11-ScriptsAndConditionals.ppt11-ScriptsAndConditionals.ppt
11-ScriptsAndConditionals.ppt
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
9-java language basics part3
9-java language basics part39-java language basics part3
9-java language basics part3
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2
 
Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to Javascript
 
Java
JavaJava
Java
 
Java input Scanner
Java input Scanner Java input Scanner
Java input Scanner
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one
 
week4_lec2_switch-statement.pptx
week4_lec2_switch-statement.pptxweek4_lec2_switch-statement.pptx
week4_lec2_switch-statement.pptx
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 

More from Mahmoud Alfarra

Chapter 10: hashing data structure
Chapter 10:  hashing data structureChapter 10:  hashing data structure
Chapter 10: hashing data structureMahmoud Alfarra
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structureMahmoud Alfarra
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structureMahmoud Alfarra
 
Chapter 7: Queue data structure
Chapter 7:  Queue data structureChapter 7:  Queue data structure
Chapter 7: Queue data structureMahmoud Alfarra
 
Chapter 6: stack data structure
Chapter 6:  stack data structureChapter 6:  stack data structure
Chapter 6: stack data structureMahmoud Alfarra
 
Chapter 5: linked list data structure
Chapter 5: linked list data structureChapter 5: linked list data structure
Chapter 5: linked list data structureMahmoud Alfarra
 
Chapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structureChapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structureMahmoud Alfarra
 
Chapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structureChapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structureMahmoud Alfarra
 
Chapter 2: array and array list data structure
Chapter 2: array and array list  data structureChapter 2: array and array list  data structure
Chapter 2: array and array list data structureMahmoud Alfarra
 
Chapter1 intro toprincipleofc#_datastructure_b_cs
Chapter1  intro toprincipleofc#_datastructure_b_csChapter1  intro toprincipleofc#_datastructure_b_cs
Chapter1 intro toprincipleofc#_datastructure_b_csMahmoud Alfarra
 
Chapter 0: introduction to data structure
Chapter 0: introduction to data structureChapter 0: introduction to data structure
Chapter 0: introduction to data structureMahmoud Alfarra
 
5 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop201020115 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop20102011Mahmoud Alfarra
 
3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computer3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computerMahmoud Alfarra
 
1 programming-using-java -introduction
1 programming-using-java -introduction1 programming-using-java -introduction
1 programming-using-java -introductionMahmoud Alfarra
 
تلخيص النصوص تلقائيا
تلخيص النصوص تلقائياتلخيص النصوص تلقائيا
تلخيص النصوص تلقائياMahmoud Alfarra
 
4×4×4 لتحصيل التميز
4×4×4 لتحصيل التميز4×4×4 لتحصيل التميز
4×4×4 لتحصيل التميزMahmoud Alfarra
 
Data preparation and processing chapter 2
Data preparation and processing chapter  2Data preparation and processing chapter  2
Data preparation and processing chapter 2Mahmoud Alfarra
 
Introduction to-data-mining chapter 1
Introduction to-data-mining  chapter 1Introduction to-data-mining  chapter 1
Introduction to-data-mining chapter 1Mahmoud Alfarra
 
Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)
Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)
Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)Mahmoud Alfarra
 

More from Mahmoud Alfarra (20)

Chapter 10: hashing data structure
Chapter 10:  hashing data structureChapter 10:  hashing data structure
Chapter 10: hashing data structure
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structure
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structure
 
Chapter 7: Queue data structure
Chapter 7:  Queue data structureChapter 7:  Queue data structure
Chapter 7: Queue data structure
 
Chapter 6: stack data structure
Chapter 6:  stack data structureChapter 6:  stack data structure
Chapter 6: stack data structure
 
Chapter 5: linked list data structure
Chapter 5: linked list data structureChapter 5: linked list data structure
Chapter 5: linked list data structure
 
Chapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structureChapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structure
 
Chapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structureChapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structure
 
Chapter 2: array and array list data structure
Chapter 2: array and array list  data structureChapter 2: array and array list  data structure
Chapter 2: array and array list data structure
 
Chapter1 intro toprincipleofc#_datastructure_b_cs
Chapter1  intro toprincipleofc#_datastructure_b_csChapter1  intro toprincipleofc#_datastructure_b_cs
Chapter1 intro toprincipleofc#_datastructure_b_cs
 
Chapter 0: introduction to data structure
Chapter 0: introduction to data structureChapter 0: introduction to data structure
Chapter 0: introduction to data structure
 
3 classification
3  classification3  classification
3 classification
 
5 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop201020115 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop20102011
 
3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computer3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computer
 
1 programming-using-java -introduction
1 programming-using-java -introduction1 programming-using-java -introduction
1 programming-using-java -introduction
 
تلخيص النصوص تلقائيا
تلخيص النصوص تلقائياتلخيص النصوص تلقائيا
تلخيص النصوص تلقائيا
 
4×4×4 لتحصيل التميز
4×4×4 لتحصيل التميز4×4×4 لتحصيل التميز
4×4×4 لتحصيل التميز
 
Data preparation and processing chapter 2
Data preparation and processing chapter  2Data preparation and processing chapter  2
Data preparation and processing chapter 2
 
Introduction to-data-mining chapter 1
Introduction to-data-mining  chapter 1Introduction to-data-mining  chapter 1
Introduction to-data-mining chapter 1
 
Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)
Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)
Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)
 

Recently uploaded

GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 

Recently uploaded (20)

GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 

7 programming-using-java decision-making220102011

  • 1. Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 7 Decision Making : selection statements (cont.)
  • 2.  if...else Double-Selection Statement  Nested if...else Statements  Blocks  Switch  Be care  Practices  Emank X Mezank 2Presented & Prepared by: Mahmoud R. Alfarra
  • 3.  The if...else double-selection statement allows the programmer to specify an action to perform when the condition is true and a different action when the condition is false. 3Presented & Prepared by: Mahmoud R. Alfarra if...else Double-Selection Statement If student's grade is greater than or equal to 60 Print "Passed" Else Print "Failed" if ( grade >= 60 ) System.out.println( "Passed" ); else System.out.println( "Failed" );
  • 4. 4Presented & Prepared by: Mahmoud R. Alfarra if...else Double-Selection Statement X<=0 yes F(x)= XF(x)= - X NO Write a program to code the above flowchart HW 7.1
  • 5.  Write a program to receive an integer from user and then print if it is an even or an odd 5Presented & Prepared by: Mahmoud R. Alfarra Example: Print Even or Odd Write the pseudo code and flowchart of the above exampleHW 7.2
  • 6. 6Presented & Prepared by: Mahmoud R. Alfarra Example: Print Even or Odd Write a program to receive two an integer from user and then print if it is an even or an oddHW 7.3
  • 7. If student's grade is greater than or equal to 90 Print "A" else If student's grade is greater than or equal to 80 Print "B" else If student's grade is greater than or equal to 70 Print "C" else If student's grade is greater than or equal to 60 Print "D" else Print "F"  A program can test multiple cases by placing if...else statements inside other if...else statements to create nested if...else statements. 7Presented & Prepared by: Mahmoud R. Alfarra Nested if...else Statements
  • 8. 8Presented & Prepared by: Mahmoud R. Alfarra if...else Double-Selection Statement X<=50 yes return “Success” return fail NO X<=80 yesNO return “pass”
  • 9.  Write a program to receive the user name and then password from user, and if the user name matches “onway2allah” and the password matches “muslim4ever”, the program print “open”.  Else the program print “pass is mismatched” or & “user is mismatched”. 9Presented & Prepared by: Mahmoud R. Alfarra Example: Privacy login Write the pseudo code and flowchart of the above exampleHW 7.4
  • 10. 10Presented & Prepared by: Mahmoud R. Alfarra Write a program to receive two an integer from user and then print if it is an even or an oddHW 7.5 Example: Privacy login
  • 11. 11Presented & Prepared by: Mahmoud R. Alfarra Comparing strings : Be care Comparing strings is doing by using (ComparTo) method, not by == . Using the following formula: String1.ComparTo(string2) , this comparison results: • 1 : means the string1 is larger than string2 • -1: means the string2 is larger than string1 • 0: means the two strings are equal Using the following formula: “Ali”.ComparTo(“zain”) = 1 “Ali”.ComparTo(“Ali”) = 0 “yahia”.ComparTo(“ahmad”) = -1
  • 12.  The if statement normally expects only one statement in its body.  To include several statements in the body of an if (or the body of an else), enclose the statements in braces ({ and }).  A set of statements contained within a pair of braces is called a block. 12Presented & Prepared by: Mahmoud R. Alfarra Blocks
  • 13.  A block can be placed anywhere in a program that a single statement can be placed. 13Presented & Prepared by: Mahmoud R. Alfarra Blocks Forgetting both of the braces that delimit a block will lead to logic error in a program. Forgetting one of the braces that delimits a block will lead to syntax error in a program.
  • 14. 14Presented & Prepared by: Mahmoud R. Alfarra Example: Blocks if ( grade >= 60 ) System.out.println( "Passed" ); else { System.out.println( "Failed" ); System.out.println( "You must take this course again." ); }  All the instructions into the block are related to the if and else …
  • 15.  Java provides the switch multiple-selection statement to perform different actions based on the possible values of an integer variable or expression.  Each action is associated with the value of a constant integral expression. 15Presented & Prepared by: Mahmoud R. Alfarra Switch A constant value in expression of type byte, short, int or char, but not long.
  • 16. 16Presented & Prepared by: Mahmoud R. Alfarra Formula: Switch switch (expr.) { case x: // instructions break; case y: // instructions break; . . . default : // instructions }
  • 17.  Write a program to receive an integer from user and then print the day of this number as ▪ 1 : Saturday ▪ 2 : Sunday ▪ …. ▪ …. 17Presented & Prepared by: Mahmoud R. Alfarra Example: Print Days Write the pseudo code and flowchart of the above exampleHW 7.6
  • 18. 18Presented & Prepared by: Mahmoud R. Alfarra Example: Print Days Re-Write this program using one of if statements HW 7.7
  • 19. ‫تعاىل‬ ‫هللا‬ ‫قال‬: (‫املنفوش‬ ‫كالعهن‬‫اجلبال‬ ‫تكون‬ ‫يوم‬) 19Presented & Prepared by: Mahmoud R. Alfarra
  • 20. Practices 20Presented & Prepared by: Mahmoud R. Alfarra