SlideShare a Scribd company logo
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 (19)

PDF
Operators, control statements represented in java
TharuniDiddekunta
 
PPT
Exception handling in c++ by manoj vasava
Manoj_vasava
 
PDF
Chapter 3 branching v4
Sunarto Quek
 
DOCX
Cis 355 i lab 2 of 6
helpido9
 
DOCX
Cis 355 ilab 2 of 6
comp274
 
PPT
Class 9 Lecture Notes
Stephen Parsons
 
PDF
Fundamentals of programming)
jakejakejake2
 
PDF
The pseudocode
Asha Sari
 
DOCX
Ternary operator
Lahore Garrison University
 
DOCX
Cis 355 i lab 1 of 6
solutionjug4
 
PPTX
Vb decision making statements
pragya ratan
 
PPT
C# Exceptions Handling
sharqiyem
 
PPTX
Intro To C++ - Class 12 - For, do … While
Blue Elephant Consulting
 
PPT
Lecture 1
Mohammed Saleh
 
PDF
Error handling and debugging
salissal
 
PPTX
Debugging
nicky_walters
 
PDF
CIS 1403 lab 4 selection
Hamad Odhabi
 
DOCX
Oop lab assignment 01
Drjilesh
 
DOCX
Exception handling
vishal choudhary
 
Operators, control statements represented in java
TharuniDiddekunta
 
Exception handling in c++ by manoj vasava
Manoj_vasava
 
Chapter 3 branching v4
Sunarto Quek
 
Cis 355 i lab 2 of 6
helpido9
 
Cis 355 ilab 2 of 6
comp274
 
Class 9 Lecture Notes
Stephen Parsons
 
Fundamentals of programming)
jakejakejake2
 
The pseudocode
Asha Sari
 
Ternary operator
Lahore Garrison University
 
Cis 355 i lab 1 of 6
solutionjug4
 
Vb decision making statements
pragya ratan
 
C# Exceptions Handling
sharqiyem
 
Intro To C++ - Class 12 - For, do … While
Blue Elephant Consulting
 
Lecture 1
Mohammed Saleh
 
Error handling and debugging
salissal
 
Debugging
nicky_walters
 
CIS 1403 lab 4 selection
Hamad Odhabi
 
Oop lab assignment 01
Drjilesh
 
Exception handling
vishal choudhary
 

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

PPT
Chapter 1 nested control structures
Khirulnizam Abd Rahman
 
PPT
Chapter 1 Nested Control Structures
Khirulnizam Abd Rahman
 
PPTX
Flow of control by deepak lakhlan
Deepak Lakhlan
 
PPTX
Java chapter 3
Abdii Rashid
 
PPT
Lecture 3
Soran University
 
PPT
Selection Control Structures
PRN USM
 
PPTX
6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA
EG20910848921ISAACDU
 
PPT
Introduction to java programming part 2
university of education,Lahore
 
PPS
Control statements
kamal kotecha
 
PPTX
control statements
Azeem Sultan
 
PPT
Introduction to Java Programming Part 2
university of education,Lahore
 
PPT
jhtp9_ch04.ppt
DrCMeenakshiVISTAS
 
PPTX
130706266060138191
Tanzeel Ahmad
 
PDF
UNIT 2 PPT.pdf
DhanushKumar610673
 
PPT
Cprogrammingprogramcontrols
teach4uin
 
PPT
Comp102 lec 5.1
Fraz Bakhsh
 
PDF
nuts and bolts of c++
guestfb6ada
 
PDF
Flow control in c++
Subhasis Nayak
 
PPTX
Computer programming 2 Lesson 9
MLG College of Learning, Inc
 
PPTX
Computer programming 2 - Lesson 7
MLG College of Learning, Inc
 
Chapter 1 nested control structures
Khirulnizam Abd Rahman
 
Chapter 1 Nested Control Structures
Khirulnizam Abd Rahman
 
Flow of control by deepak lakhlan
Deepak Lakhlan
 
Java chapter 3
Abdii Rashid
 
Lecture 3
Soran University
 
Selection Control Structures
PRN USM
 
6 Control Structures-1.pptxAAAAAAAAAAAAAAAAAAAAA
EG20910848921ISAACDU
 
Introduction to java programming part 2
university of education,Lahore
 
Control statements
kamal kotecha
 
control statements
Azeem Sultan
 
Introduction to Java Programming Part 2
university of education,Lahore
 
jhtp9_ch04.ppt
DrCMeenakshiVISTAS
 
130706266060138191
Tanzeel Ahmad
 
UNIT 2 PPT.pdf
DhanushKumar610673
 
Cprogrammingprogramcontrols
teach4uin
 
Comp102 lec 5.1
Fraz Bakhsh
 
nuts and bolts of c++
guestfb6ada
 
Flow control in c++
Subhasis Nayak
 
Computer programming 2 Lesson 9
MLG College of Learning, Inc
 
Computer programming 2 - Lesson 7
MLG College of Learning, Inc
 
Ad

More from Mahmoud Alfarra (20)

PPT
Computer Programming, Loops using Java - part 2
Mahmoud Alfarra
 
PPT
Chapter 10: hashing data structure
Mahmoud Alfarra
 
PPT
Chapter9 graph data structure
Mahmoud Alfarra
 
PPT
Chapter 8: tree data structure
Mahmoud Alfarra
 
PPT
Chapter 7: Queue data structure
Mahmoud Alfarra
 
PPT
Chapter 6: stack data structure
Mahmoud Alfarra
 
PPT
Chapter 5: linked list data structure
Mahmoud Alfarra
 
PPT
Chapter 4: basic search algorithms data structure
Mahmoud Alfarra
 
PPT
Chapter 3: basic sorting algorithms data structure
Mahmoud Alfarra
 
PPT
Chapter 2: array and array list data structure
Mahmoud Alfarra
 
PPT
Chapter1 intro toprincipleofc#_datastructure_b_cs
Mahmoud Alfarra
 
PPT
Chapter 0: introduction to data structure
Mahmoud Alfarra
 
PPTX
3 classification
Mahmoud Alfarra
 
PPT
5 programming-using-java intro-tooop20102011
Mahmoud Alfarra
 
PPT
3 programming-using-java introduction-to computer
Mahmoud Alfarra
 
PPT
1 programming-using-java -introduction
Mahmoud Alfarra
 
PPTX
تلخيص النصوص تلقائيا
Mahmoud Alfarra
 
PDF
4×4×4 لتحصيل التميز
Mahmoud Alfarra
 
PPTX
Data preparation and processing chapter 2
Mahmoud Alfarra
 
PPTX
Introduction to-data-mining chapter 1
Mahmoud Alfarra
 
Computer Programming, Loops using Java - part 2
Mahmoud Alfarra
 
Chapter 10: hashing data structure
Mahmoud Alfarra
 
Chapter9 graph data structure
Mahmoud Alfarra
 
Chapter 8: tree data structure
Mahmoud Alfarra
 
Chapter 7: Queue data structure
Mahmoud Alfarra
 
Chapter 6: stack data structure
Mahmoud Alfarra
 
Chapter 5: linked list data structure
Mahmoud Alfarra
 
Chapter 4: basic search algorithms data structure
Mahmoud Alfarra
 
Chapter 3: basic sorting algorithms data structure
Mahmoud Alfarra
 
Chapter 2: array and array list data structure
Mahmoud Alfarra
 
Chapter1 intro toprincipleofc#_datastructure_b_cs
Mahmoud Alfarra
 
Chapter 0: introduction to data structure
Mahmoud Alfarra
 
3 classification
Mahmoud Alfarra
 
5 programming-using-java intro-tooop20102011
Mahmoud Alfarra
 
3 programming-using-java introduction-to computer
Mahmoud Alfarra
 
1 programming-using-java -introduction
Mahmoud Alfarra
 
تلخيص النصوص تلقائيا
Mahmoud Alfarra
 
4×4×4 لتحصيل التميز
Mahmoud Alfarra
 
Data preparation and processing chapter 2
Mahmoud Alfarra
 
Introduction to-data-mining chapter 1
Mahmoud Alfarra
 
Ad

Recently uploaded (20)

PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
epi editorial commitee meeting presentation
MIPLM
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
infertility, types,causes, impact, and management
Ritu480198
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Difference between write and update in odoo 18
Celine George
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
Horarios de distribución de agua en julio
pegazohn1978
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Controller Request and Response in Odoo18
Celine George
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 

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