Lesson3 Java Conditional Statements
Lesson3 Java Conditional Statements
CONTROL STRUCTURES
Sequence
Selection/Conditional
Repetition/Iteration
SEQUENTIAL FLOW
Statement if
If Statement True
Switch Case
ITERATION FLOW
Problem Case #2
Display “Positive Number” if the value is a positive number (1,2,3..so
on...)
Problem Case #3
Display “Positive Number” if the value is a positive number.
Otherwise, display “Negative Number”.
Problem Case #4
Display “Zero” if the value is zero (0). Display “Positive Number” if the
number is a positive number. Otherwise, display “Negative Number”.
CONDITIONAL STATEMENTS - IF
Note that if is in lowercase letters. Uppercase letters (If or IF) will generate an error.
CONDITIONAL STATEMENTS - IF
Problem Case #1
OUTPUT:
Positive Number
CONDITIONAL STATEMENTS - IF
Problem Case #2
OUTPUT:
Positive Number
CONDITIONAL STATEMENTS – IF/ELSE
https://www.w3schools.com/java/java_conditions.asp
CONDITIONAL STATEMENTS - IF/ELSE
Problem Case #3
OUTPUT:
Negative Number
CONDITIONAL STATEMENTS – IF/ELSE IF/ELSE
https://www.w3schools.com/java/java_conditions.asp
CONDITIONAL STATEMENTS - IF/ELSE IF/ELSE
Problem Case #4
Display “Zero” if the value is zero (0). Display “Positive Number” if the
number is a positive number. Otherwise, display “Negative Number”.
OUTPUT:
Zero
CONDITIONAL STATEMENTS – SWITCH CASE
https://www.w3schools.com/java/java_switch.asp
CONDITIONAL STATEMENTS – SWITCH CASE
1 Sunday
2 Monday
3 Tuesday
4 Wednesday
5 Thursday
6 Friday
7 Saturday
OUTPUT:
Wednesday