Professional Documents
Culture Documents
Lesson13 - DLP14 - Java Conditional Statements
Lesson13 - DLP14 - Java Conditional Statements
Lesson13 - DLP14 - Java Conditional Statements
Name: Date:
Grade/Section: Rating:
Teacher:
CONCEPTS
Conditional Statements
Allows a program to take action based on the given condition. It makes our program
smarter. Typically, it compares two values so that our program can decide what
action should be taken.
The if Statement
if (condition) {
}
ARELLANO UNIVERSITY – PLARIDEL CAMPUS
53 General Kalentong St. Mandaluyong
Senior High School
Dynamic Learning Program
Example
Use the else statement to specify a block of code to be executed if the condition
is false.
Syntax
if (condition) {
} else {
Example
System.out.println("Good day.");
} else {
System.out.println("Good evening.");
Use the else if statement to specify a new condition if the first condition is false.
Syntax
if (condition1) {
} else if (condition2) {
} else {
Example
int time = 22;
if (time < 10) {
System.out.println("Good morning.");
} else if (time < 20) {
System.out.println("Good day.");
} else {
System.out.println("Good evening.");
}
// Outputs "Good evening."
Java Switch Statements
Use the switch statement to select one of many code blocks to be executed.
Syntax
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
ARELLANO UNIVERSITY – PLARIDEL CAMPUS
53 General Kalentong St. Mandaluyong
Senior High School
Dynamic Learning Program
}
Example
int day = 4;
switch (day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
case 6:
System.out.println("Saturday");
break;
case 7:
System.out.println("Sunday");
break;
}
// Outputs "Thursday" (day 4)
The default keyword specifies some code to run if there is no case match:
QUESTIONS/ACTIVITY QUESTIONS:
1.It is use to specify a block of code to be executed if the condition is false.
Else statement
2.It is use to specify a new condition to test, if the first condition is false
Else if statement
3.It is use to specify a block of code to be executed, if a specified condition is true
If statement
ARELLANO UNIVERSITY – PLARIDEL CAMPUS
53 General Kalentong St. Mandaluyong
Senior High School
Dynamic Learning Program
If average:
Average Scale Description
90 - 100 Outstanding
85 - 89 Very Satisfactory
80 - 84 Satisfactory
75 - 79 Fairly Satisfactory
Below 75 Did Not Meet
Expectations