SlideShare a Scribd company logo
1 | 8
USING CONDITIONAL STATEMENTS:
SWITCH STATEMENTS
Java Programming – Using Conditional Statements: Switch Statements
WHAT IS A CONDITIONAL STATEMENT?
A conditional statement in Python programming is a type of statement that compares the values of two or
more operands.
An operand refers to the data that is used by the program either for comparison, manipulation, or
mathematical operation. An operand can be:
▪ a value inputted by the user
▪ a value set by the programmer inside the program
The results of the comparison using a conditional statement can result to either a TRUE or FALSE response.
▪ The TRUE response signifies that the values of operands are equal to one another or it is within the
range provided by one of the operands.
▪ The FALSE response indicates that the values of operands are not equal to one another or it is outside
the range provided by one of the operands.
Programmers commonly use truth tables to determine whether the comparison between the data and the
values set in the program will yield either a TRUE or FALSE response. The truth table is a visual
representation that displays the inputted data, the set value, the argument, and the response.
TRUTH TABLE
Inputted Data Set Value Argument Response
8 5 8 > 5 True
20 20 20 != 20 False
Yes Yes Yes == Yes True
F f F == f False
25 15 25 >= 15 True
In this lecture, we have to operands labelled as inputted data and set value. The “inputted data” refers to the
data that was entered by the user in the program. The “set value” is the data that was specifically assigned
in the program. The set value will serve as our basis for comparison that will check whether inputted data
is equal to it or within its range.
The “argument” is a statement that indicates how the operands are being compared to one another.
Arguments in Python are expressed by using comparison operators. The comparison operators available in
Python programming were as follows:
COMPARISON
OPERATOR
DEFINITION
SAMPLE
STATEMENT
== A comparison operator that checks if the operands are EQUAL to one another. a == b
!=
A comparison operator that checks if the operands are NOT EQUAL to one
another.
a != b
>
A comparison operator that checks if value on the left side of the argument is
GREATER THAN the value on the right side of the argument.
a > b
<
A comparison operator that checks if value on the left side of the argument is
LESS THAN the value on the right side of the argument.
a < b
>=
A comparison operator that checks if value on the left side of the argument is
GREATER THAN OR EQUAL TO the value on the right side of the argument.
a >= b
<=
A comparison operator that checks if value on the left side of the argument is
LESS THAN OR EQUAL TO the value on the right side of the argument.
a <= b
The “response” serves as the result of comparing the operands. The response can either be TRUE or FALSE
based on the conditions that will determine whether the operands matches or does not match with one
another.
2 | 8
USING CONDITIONAL STATEMENTS:
SWITCH STATEMENTS
Java Programming – Using Conditional Statements: Switch Statements
PRACTICE WITH TRUTH TABLES
Complete the table by filling up the Response Column with either TRUE or FALSE:
TRUTH TABLE
No. Inputted Data Set Value Argument Response
1 Rowell rowell Rowell == rowell
2 15 15 15 != 15
3 male Male male == Male
4 25 15 25 >= 15
5 1.3 4 1.3 <= 4
6 15 18 15 == 18
7 giraffe rhino giraffe == rhino
8 90 91 90 != 91
9 48 45 48 >= 45
10 107 92 107 < 92
USING SWITCH STATEMENT
Now that we know how conditional statements work it is time for us to learn how to use one of the most
basic form of conditional statements called switch statement.
The switch statement is a type of conditional statement that is used to execute a block of code by comparing
an operand to a specific value that was set in the program.
The switch statement uses conditions that are labeled as cases. Each case is composed of the case,
executable block of code and a break statement.
Consider this example of a case:
Case
It refers to the statement that contains the condition.
In the source code above, the line case “January”: details the condition where it asks if the operand
presented to it is equal to January.
Executable Block of Code
The executable block of codes contains the instructions that the program will have to perform once the
condition on the case matches the value of the operand.
In our source code sample, the messages "The month is named after the Roman God, Janus." and "The
presider of doors and beginnings." will be displayed on the screen if the operand is equal to January.
If the operand fails to match the condition, the program will skip reading the executable block of code
and jump directly to the next case.
Break Statement
The break statement indicates the end of the case. It signals the program to stop reading the next line
of codes within the switch statement.
If the program reached the line that contains the break; statement, the program will skip all other
conditions and jump to the line of code that is outside the switch statement.
3 | 8
USING CONDITIONAL STATEMENTS:
SWITCH STATEMENTS
Java Programming – Using Conditional Statements: Switch Statements
Sample Program 1:
Create a Java program that will require the user to input any number from 1-3. The program will display an
output statement based on these given conditions:
▪ If the user inputted number 1, it will display the sentence “You entered the number ONE.”.
▪ If the user inputted number 2, it will display the sentence “You entered the number TWO.”.
▪ If the user inputted number 3, it will display the sentence “You entered the number THREE.”.
▪ If the user inputted any number that is outside the range, it will display the sentence “The number
you have entered is outside of the range given.”.
Simulation of Program 1:
USER’S INPUT PROGRAM’S OUTPUT
1
2
3
8
Source Code of Sample Program 1:
4 | 8
USING CONDITIONAL STATEMENTS:
SWITCH STATEMENTS
Java Programming – Using Conditional Statements: Switch Statements
Let us examine the code:
▪ Line 1 contains the package name of our Java program named “switch_statement”.
▪ Line 2 is where we import the scanner in our program. In our previous sessions, we have learned
that the scanner is a class in Java program that enables the program to get input from the user
▪ Line 4 contains the class name of our Java program named “Switch_Statement” while line 5 contains
an open bracket ( { ) which indicates the beginning of the class.
▪ Line 7 contains the header of our main program while line 8 contains an open bracket ( { ) which
indicates the beginning of the program body.
▪ On Line 9 we introduced our scanner to the program and assigned the name “mitis” to it. The new
Scanner statement declares mitis as a new scanner in the program that takes in inputs from the
user by using the System.in function.
▪ Line 10 is used to display message on the screen using the print ( ) function. The line explicitly
instructed the program to show the message “Enter any number from 1-3” on the display screen.
▪ Line 11 displays the procedure that prepares the program to accept input from the user. The int num
part of the statement declares the incoming input from the user as an integer (int) with the assigned
name “num”. The mitis.nextInt( ) tells the program that the input will be captured using the scanner
named mitis and that the input should be treated as an integer.
▪ Lines 12-26 details the procedure of using the switch statement.
5 | 8
USING CONDITIONAL STATEMENTS:
SWITCH STATEMENTS
Java Programming – Using Conditional Statements: Switch Statements
• Line 12 displays the use of the function switch ( ). The identifier num that was enclosed in
parentheses instructs the program that the value that was contained in num will be the value that
will be used for the switch statement. The line 13 contains an open bracket ( { ) which indicates
the beginning of the switch statement.
• Line 14 contains the first condition of the program which checks if the value contained in num is
equal to 1. If num is equal to one then the display message on line 15 will be shown on the screen.
The line 16 contains the break statement which indicates the end of the first case.
Note:
If the value of num is not equal to 1, the program will skip reading lines 15 and 16 and
automatically jumps to line 17.
• Line 17 contains the second condition which checks if the value contained in num is equal to 2. If
num is equal to two then the display message on line 18 will be shown on the screen. The line 19
contains the break statement which indicates the end of the second case.
Note:
If the value of num is not equal to 2, the program will skip reading lines 18 and 19 and
automatically jumps to line 20.
• Line 20 contains the third condition which checks if the value contained in num is equal to 3. If
num is equal to three then the display message on line 21 will be shown on the screen. The line
22 contains the break statement which indicates the end of the third case.
Note:
If the value of num is not equal to 3, the program will skip reading lines 21 and 22 and
automatically jumps to line 23.
• Line 23 contains the default condition which accepts the input if it fails to match with any of the
conditions written above it. If the program has reached this line of code it will automatically
display the message on line 24. The line 22 contains the break statement which indicates the end
of the default case. The line 26 contains an close bracket ( } ) which indicates the end of the switch
statement.
6 | 8
USING CONDITIONAL STATEMENTS:
SWITCH STATEMENTS
Java Programming – Using Conditional Statements: Switch Statements
Sample Program 2:
Create a Java program that will require the user to choose an animal among the list of choices. The list of
animals include dog, cat, bird, and fish. After the user have entered their choice of pet, the program will tell
what personality do they have based on their chosen pet.
▪ If the user inputted dog, it will display the sentence “You have an outgoing personality.”.
▪ If the user inputted cat, it will display the sentence “You have a conservative personality.”.
▪ If the user inputted bird, it will display the sentence “You have caring personality.”.
▪ If the user inputted fish, it will display the sentence “You have a calm and stable personality.”.
▪ If the user inputted a name of an animal that is not included in the list, it will display the sentence
“The animal you have entered is not in the list.”.
Simulation of Program 2:
USER’S INPUT PROGRAM’S OUTPUT
dog
cat
bird
fish
chicken
Source Code of Sample Program 2:
7 | 8
USING CONDITIONAL STATEMENTS:
SWITCH STATEMENTS
Java Programming – Using Conditional Statements: Switch Statements
Programming Challenge 1:
Create a Java program that will require the user to input a name of a country based on list of choices. The
list includes Philippines, Japan, Korea, and China. After the user have entered their preferred country, the
program will display the equivalent of “I love you” in the chosen language.
▪ If the user inputted Philippines, it will display the sentence “Mahal kita.”.
▪ If the user inputted Japan, it will display the sentence “Aishiteru”.
▪ If the user inputted Korea, it will display the sentence “Saranghaeyo.”.
▪ If the user inputted China, it will display the sentence “Wo ai ni”.
▪ If the user inputted a name of a country that is not included in the list, it will display the sentence
“The country you have entered is not in the list.”.
Simulation of Program 2:
USER’S INPUT PROGRAM’S OUTPUT
Philippines
Japan
Korea
China
Malaysia
Programming Challenge 2:
Create a Java program that will require the user to input any number from 1-12. The program will display
the name of the month that corresponds to the user’s input.
▪ If the user inputted number 1, it will display the sentence “January is the 1st month of the year”.
▪ If the user inputted number 2, it will display the sentence “February is the 2nd month of the year”.
▪ If the user inputted number 3, it will display the sentence “March is the 3rd month of the year”.
▪ If the user inputted number 4, it will display the sentence “April is the 4th month of the year”.
▪ If the user inputted number 5, it will display the sentence “May is the 5th month of the year”.
▪ If the user inputted number 6, it will display the sentence “June is the 6th month of the year”.
▪ If the user inputted number 7, it will display the sentence “July is the 7th month of the year”.
▪ If the user inputted number 8, it will display the sentence “August is the 8th month of the year”.
▪ If the user inputted number 9, it will display the sentence “September is the 9th month of the year”.
▪ If the user inputted number 10, it will display the sentence “October is the 10th month of the year”.
▪ If the user inputted number 11, it will display the sentence “November is the 11th month of the year”.
▪ If the user inputted number 12, it will display the sentence “December is the 12th month of the year”.
▪ If the user inputted any number that is outside the range, it will display the sentence “Our calendar
only has 12 months”.
Simulation of Program 2:
USER’S INPUT PROGRAM’S OUTPUT
1
2
45
8 | 8
USING CONDITIONAL STATEMENTS:
SWITCH STATEMENTS
Java Programming – Using Conditional Statements: Switch Statements
Ad

More Related Content

What's hot (20)

Stack
StackStack
Stack
Seema Sharma
 
INHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptxINHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptx
NITHISG1
 
String Manipulation in Python
String Manipulation in PythonString Manipulation in Python
String Manipulation in Python
Pooja B S
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and Streams
Anton Keks
 
Types of exceptions
Types of exceptionsTypes of exceptions
Types of exceptions
myrajendra
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
Raja Sekhar
 
for loop in java
for loop in java for loop in java
for loop in java
Majid Ali
 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
vishal choudhary
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Edureka!
 
Python set
Python setPython set
Python set
Mohammed Sikander
 
Java Constructors
Java ConstructorsJava Constructors
Java Constructors
Saumya Som
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
Java2Blog
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)
Bilal Amjad
 
Cheat Sheet java
Cheat Sheet javaCheat Sheet java
Cheat Sheet java
arkslideshareacc
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Madishetty Prathibha
 
Python GUI
Python GUIPython GUI
Python GUI
LusciousLarryDas
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
Farooq Baloch
 
Java interface
Java interfaceJava interface
Java interface
BHUVIJAYAVELU
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
Sunil OS
 
INHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptxINHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptx
NITHISG1
 
String Manipulation in Python
String Manipulation in PythonString Manipulation in Python
String Manipulation in Python
Pooja B S
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and Streams
Anton Keks
 
Types of exceptions
Types of exceptionsTypes of exceptions
Types of exceptions
myrajendra
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
Raja Sekhar
 
for loop in java
for loop in java for loop in java
for loop in java
Majid Ali
 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
vishal choudhary
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Edureka!
 
Java Constructors
Java ConstructorsJava Constructors
Java Constructors
Saumya Som
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
Java2Blog
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)
Bilal Amjad
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
Farooq Baloch
 

Similar to Java Programming - Conditional Statements (Switch).pdf (20)

Fundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptxFundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptx
Eyasu46
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selection
Hamad Odhabi
 
03a control structures
03a   control structures03a   control structures
03a control structures
Manzoor ALam
 
Conditional Statement - Switch Case.pptx
Conditional Statement - Switch Case.pptxConditional Statement - Switch Case.pptx
Conditional Statement - Switch Case.pptx
DheromeIngenious1
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptx
XhelalSpahiu
 
Debugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programsDebugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programs
PVS-Studio
 
Loops presentationnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Loops presentationnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnLoops presentationnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Loops presentationnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
divyapriya balasubramani
 
Control structures i
Control structures i Control structures i
Control structures i
Ahmad Idrees
 
MSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMSc COMPUTER APPLICATION
MSc COMPUTER APPLICATION
MugdhaSharma11
 
Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2
Blue Elephant Consulting
 
Programming Fundamentals lecture 7
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7
REHAN IJAZ
 
Comparison instructions, AB, Siemens and AB CCW
Comparison instructions, AB, Siemens and AB CCWComparison instructions, AB, Siemens and AB CCW
Comparison instructions, AB, Siemens and AB CCW
John Todora
 
C# language basics (Visual Studio)
C# language basics (Visual Studio) C# language basics (Visual Studio)
C# language basics (Visual Studio)
rnkhan
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)
rnkhan
 
slides03.ppt
slides03.pptslides03.ppt
slides03.ppt
Anjali127411
 
Java input Scanner
Java input Scanner Java input Scanner
Java input Scanner
Huda Alameen
 
PPS 3.3CONDITIONAL BRANCHING AND LOOPS WRITING AND EVALUATION OF CONDITIONAL...
PPS 3.3CONDITIONAL BRANCHING AND LOOPS  WRITING AND EVALUATION OF CONDITIONAL...PPS 3.3CONDITIONAL BRANCHING AND LOOPS  WRITING AND EVALUATION OF CONDITIONAL...
PPS 3.3CONDITIONAL BRANCHING AND LOOPS WRITING AND EVALUATION OF CONDITIONAL...
Sitamarhi Institute of Technology
 
As Level Computer Science Book -2
As Level Computer Science  Book -2As Level Computer Science  Book -2
As Level Computer Science Book -2
DIGDARSHAN KUNWAR
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A Review
Fernando Torres
 
Lewis_Cocking_AP_Decision_Making_For_Coding
Lewis_Cocking_AP_Decision_Making_For_CodingLewis_Cocking_AP_Decision_Making_For_Coding
Lewis_Cocking_AP_Decision_Making_For_Coding
GeorgeTsak
 
Fundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptxFundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptx
Eyasu46
 
CIS 1403 lab 4 selection
CIS 1403 lab 4 selectionCIS 1403 lab 4 selection
CIS 1403 lab 4 selection
Hamad Odhabi
 
03a control structures
03a   control structures03a   control structures
03a control structures
Manzoor ALam
 
Conditional Statement - Switch Case.pptx
Conditional Statement - Switch Case.pptxConditional Statement - Switch Case.pptx
Conditional Statement - Switch Case.pptx
DheromeIngenious1
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptx
XhelalSpahiu
 
Debugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programsDebugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programs
PVS-Studio
 
Loops presentationnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Loops presentationnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnLoops presentationnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Loops presentationnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
divyapriya balasubramani
 
Control structures i
Control structures i Control structures i
Control structures i
Ahmad Idrees
 
MSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMSc COMPUTER APPLICATION
MSc COMPUTER APPLICATION
MugdhaSharma11
 
Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2
Blue Elephant Consulting
 
Programming Fundamentals lecture 7
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7
REHAN IJAZ
 
Comparison instructions, AB, Siemens and AB CCW
Comparison instructions, AB, Siemens and AB CCWComparison instructions, AB, Siemens and AB CCW
Comparison instructions, AB, Siemens and AB CCW
John Todora
 
C# language basics (Visual Studio)
C# language basics (Visual Studio) C# language basics (Visual Studio)
C# language basics (Visual Studio)
rnkhan
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)
rnkhan
 
Java input Scanner
Java input Scanner Java input Scanner
Java input Scanner
Huda Alameen
 
PPS 3.3CONDITIONAL BRANCHING AND LOOPS WRITING AND EVALUATION OF CONDITIONAL...
PPS 3.3CONDITIONAL BRANCHING AND LOOPS  WRITING AND EVALUATION OF CONDITIONAL...PPS 3.3CONDITIONAL BRANCHING AND LOOPS  WRITING AND EVALUATION OF CONDITIONAL...
PPS 3.3CONDITIONAL BRANCHING AND LOOPS WRITING AND EVALUATION OF CONDITIONAL...
Sitamarhi Institute of Technology
 
As Level Computer Science Book -2
As Level Computer Science  Book -2As Level Computer Science  Book -2
As Level Computer Science Book -2
DIGDARSHAN KUNWAR
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A Review
Fernando Torres
 
Lewis_Cocking_AP_Decision_Making_For_Coding
Lewis_Cocking_AP_Decision_Making_For_CodingLewis_Cocking_AP_Decision_Making_For_Coding
Lewis_Cocking_AP_Decision_Making_For_Coding
GeorgeTsak
 
Ad

More from ROWELL MARQUINA (20)

WSAT Lesson 3 - Introduction to HTML.pdf
WSAT Lesson 3 -  Introduction to HTML.pdfWSAT Lesson 3 -  Introduction to HTML.pdf
WSAT Lesson 3 - Introduction to HTML.pdf
ROWELL MARQUINA
 
PLD Lesson 5 - Displaying Text and Comment on the Screen.pdf
PLD Lesson 5 - Displaying Text and Comment on the Screen.pdfPLD Lesson 5 - Displaying Text and Comment on the Screen.pdf
PLD Lesson 5 - Displaying Text and Comment on the Screen.pdf
ROWELL MARQUINA
 
COM Lesson 1 - Introduction to Computer Organization and Management.pdf
COM Lesson 1 - Introduction to Computer Organization and Management.pdfCOM Lesson 1 - Introduction to Computer Organization and Management.pdf
COM Lesson 1 - Introduction to Computer Organization and Management.pdf
ROWELL MARQUINA
 
PROG3 Lesson 4 - Setting Up the VS Code Environment.pdf
PROG3 Lesson 4 - Setting Up the VS Code Environment.pdfPROG3 Lesson 4 - Setting Up the VS Code Environment.pdf
PROG3 Lesson 4 - Setting Up the VS Code Environment.pdf
ROWELL MARQUINA
 
PLD Lesson 4 - Setting Up the VS Code Environment.pdf
PLD Lesson 4 - Setting Up the VS Code Environment.pdfPLD Lesson 4 - Setting Up the VS Code Environment.pdf
PLD Lesson 4 - Setting Up the VS Code Environment.pdf
ROWELL MARQUINA
 
PLD Lesson 3 - Flowcharting Conditional Statements.pdf
PLD Lesson 3 - Flowcharting Conditional Statements.pdfPLD Lesson 3 - Flowcharting Conditional Statements.pdf
PLD Lesson 3 - Flowcharting Conditional Statements.pdf
ROWELL MARQUINA
 
FoR Lesson 1 - Introduction to Research.pdf
FoR Lesson 1 - Introduction to Research.pdfFoR Lesson 1 - Introduction to Research.pdf
FoR Lesson 1 - Introduction to Research.pdf
ROWELL MARQUINA
 
Lesson 3 - Understanding Professional Ethics.pdf
Lesson 3 - Understanding Professional Ethics.pdfLesson 3 - Understanding Professional Ethics.pdf
Lesson 3 - Understanding Professional Ethics.pdf
ROWELL MARQUINA
 
WSAT Lesson 2 - Introduction to World Wide Web.pdf
WSAT Lesson 2 - Introduction to World Wide Web.pdfWSAT Lesson 2 - Introduction to World Wide Web.pdf
WSAT Lesson 2 - Introduction to World Wide Web.pdf
ROWELL MARQUINA
 
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdfWSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
ROWELL MARQUINA
 
ITSP Lesson 2 - Ethical Principles and Theories.pdf
ITSP Lesson 2 - Ethical Principles and Theories.pdfITSP Lesson 2 - Ethical Principles and Theories.pdf
ITSP Lesson 2 - Ethical Principles and Theories.pdf
ROWELL MARQUINA
 
ITSP Lesson 1 - Ethics and Its History.pdf
ITSP Lesson 1 - Ethics and Its History.pdfITSP Lesson 1 - Ethics and Its History.pdf
ITSP Lesson 1 - Ethics and Its History.pdf
ROWELL MARQUINA
 
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdfWSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
ROWELL MARQUINA
 
Lesson 2 - Algorithm and Flowcharting.pdf
Lesson 2 - Algorithm and Flowcharting.pdfLesson 2 - Algorithm and Flowcharting.pdf
Lesson 2 - Algorithm and Flowcharting.pdf
ROWELL MARQUINA
 
Introduction to Programming and Languages.pdf
Introduction to Programming and Languages.pdfIntroduction to Programming and Languages.pdf
Introduction to Programming and Languages.pdf
ROWELL MARQUINA
 
QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdf
ROWELL MARQUINA
 
QMMS Lesson 2 - Using Excel Formula.pptx
QMMS Lesson 2 - Using Excel Formula.pptxQMMS Lesson 2 - Using Excel Formula.pptx
QMMS Lesson 2 - Using Excel Formula.pptx
ROWELL MARQUINA
 
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdfHCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
ROWELL MARQUINA
 
HCI Lesson 1 - Introduction to Human-Computer Interaction.pdf
HCI Lesson 1 - Introduction to Human-Computer Interaction.pdfHCI Lesson 1 - Introduction to Human-Computer Interaction.pdf
HCI Lesson 1 - Introduction to Human-Computer Interaction.pdf
ROWELL MARQUINA
 
DS Lesson 2 - Subsets, Supersets and Power Set.pdf
DS Lesson 2 - Subsets, Supersets and Power Set.pdfDS Lesson 2 - Subsets, Supersets and Power Set.pdf
DS Lesson 2 - Subsets, Supersets and Power Set.pdf
ROWELL MARQUINA
 
WSAT Lesson 3 - Introduction to HTML.pdf
WSAT Lesson 3 -  Introduction to HTML.pdfWSAT Lesson 3 -  Introduction to HTML.pdf
WSAT Lesson 3 - Introduction to HTML.pdf
ROWELL MARQUINA
 
PLD Lesson 5 - Displaying Text and Comment on the Screen.pdf
PLD Lesson 5 - Displaying Text and Comment on the Screen.pdfPLD Lesson 5 - Displaying Text and Comment on the Screen.pdf
PLD Lesson 5 - Displaying Text and Comment on the Screen.pdf
ROWELL MARQUINA
 
COM Lesson 1 - Introduction to Computer Organization and Management.pdf
COM Lesson 1 - Introduction to Computer Organization and Management.pdfCOM Lesson 1 - Introduction to Computer Organization and Management.pdf
COM Lesson 1 - Introduction to Computer Organization and Management.pdf
ROWELL MARQUINA
 
PROG3 Lesson 4 - Setting Up the VS Code Environment.pdf
PROG3 Lesson 4 - Setting Up the VS Code Environment.pdfPROG3 Lesson 4 - Setting Up the VS Code Environment.pdf
PROG3 Lesson 4 - Setting Up the VS Code Environment.pdf
ROWELL MARQUINA
 
PLD Lesson 4 - Setting Up the VS Code Environment.pdf
PLD Lesson 4 - Setting Up the VS Code Environment.pdfPLD Lesson 4 - Setting Up the VS Code Environment.pdf
PLD Lesson 4 - Setting Up the VS Code Environment.pdf
ROWELL MARQUINA
 
PLD Lesson 3 - Flowcharting Conditional Statements.pdf
PLD Lesson 3 - Flowcharting Conditional Statements.pdfPLD Lesson 3 - Flowcharting Conditional Statements.pdf
PLD Lesson 3 - Flowcharting Conditional Statements.pdf
ROWELL MARQUINA
 
FoR Lesson 1 - Introduction to Research.pdf
FoR Lesson 1 - Introduction to Research.pdfFoR Lesson 1 - Introduction to Research.pdf
FoR Lesson 1 - Introduction to Research.pdf
ROWELL MARQUINA
 
Lesson 3 - Understanding Professional Ethics.pdf
Lesson 3 - Understanding Professional Ethics.pdfLesson 3 - Understanding Professional Ethics.pdf
Lesson 3 - Understanding Professional Ethics.pdf
ROWELL MARQUINA
 
WSAT Lesson 2 - Introduction to World Wide Web.pdf
WSAT Lesson 2 - Introduction to World Wide Web.pdfWSAT Lesson 2 - Introduction to World Wide Web.pdf
WSAT Lesson 2 - Introduction to World Wide Web.pdf
ROWELL MARQUINA
 
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdfWSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
ROWELL MARQUINA
 
ITSP Lesson 2 - Ethical Principles and Theories.pdf
ITSP Lesson 2 - Ethical Principles and Theories.pdfITSP Lesson 2 - Ethical Principles and Theories.pdf
ITSP Lesson 2 - Ethical Principles and Theories.pdf
ROWELL MARQUINA
 
ITSP Lesson 1 - Ethics and Its History.pdf
ITSP Lesson 1 - Ethics and Its History.pdfITSP Lesson 1 - Ethics and Its History.pdf
ITSP Lesson 1 - Ethics and Its History.pdf
ROWELL MARQUINA
 
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdfWSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
WSAT Lesson 1 - Introduction to Web Systems and Technologies.pdf
ROWELL MARQUINA
 
Lesson 2 - Algorithm and Flowcharting.pdf
Lesson 2 - Algorithm and Flowcharting.pdfLesson 2 - Algorithm and Flowcharting.pdf
Lesson 2 - Algorithm and Flowcharting.pdf
ROWELL MARQUINA
 
Introduction to Programming and Languages.pdf
Introduction to Programming and Languages.pdfIntroduction to Programming and Languages.pdf
Introduction to Programming and Languages.pdf
ROWELL MARQUINA
 
QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdf
ROWELL MARQUINA
 
QMMS Lesson 2 - Using Excel Formula.pptx
QMMS Lesson 2 - Using Excel Formula.pptxQMMS Lesson 2 - Using Excel Formula.pptx
QMMS Lesson 2 - Using Excel Formula.pptx
ROWELL MARQUINA
 
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdfHCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
HCI Lesson 2 - Components of Human-Computer Interaction (HCI).pdf
ROWELL MARQUINA
 
HCI Lesson 1 - Introduction to Human-Computer Interaction.pdf
HCI Lesson 1 - Introduction to Human-Computer Interaction.pdfHCI Lesson 1 - Introduction to Human-Computer Interaction.pdf
HCI Lesson 1 - Introduction to Human-Computer Interaction.pdf
ROWELL MARQUINA
 
DS Lesson 2 - Subsets, Supersets and Power Set.pdf
DS Lesson 2 - Subsets, Supersets and Power Set.pdfDS Lesson 2 - Subsets, Supersets and Power Set.pdf
DS Lesson 2 - Subsets, Supersets and Power Set.pdf
ROWELL MARQUINA
 
Ad

Recently uploaded (20)

Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
TrsLabs - AI Agents for All - Chatbots to Multi-Agents Systems
TrsLabs - AI Agents for All - Chatbots to Multi-Agents SystemsTrsLabs - AI Agents for All - Chatbots to Multi-Agents Systems
TrsLabs - AI Agents for All - Chatbots to Multi-Agents Systems
Trs Labs
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
Make GenAI investments go further with the Dell AI Factory
Make GenAI investments go further with the Dell AI FactoryMake GenAI investments go further with the Dell AI Factory
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
The Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdfThe Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdf
Precisely
 
Play It Safe: Manage Security Risks - Google Certificate
Play It Safe: Manage Security Risks - Google CertificatePlay It Safe: Manage Security Risks - Google Certificate
Play It Safe: Manage Security Risks - Google Certificate
VICTOR MAESTRE RAMIREZ
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...Transcript: Canadian book publishing: Insights from the latest salary survey ...
Transcript: Canadian book publishing: Insights from the latest salary survey ...
BookNet Canada
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
TrsLabs - AI Agents for All - Chatbots to Multi-Agents Systems
TrsLabs - AI Agents for All - Chatbots to Multi-Agents SystemsTrsLabs - AI Agents for All - Chatbots to Multi-Agents Systems
TrsLabs - AI Agents for All - Chatbots to Multi-Agents Systems
Trs Labs
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
UiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer OpportunitiesUiPath Agentic Automation: Community Developer Opportunities
UiPath Agentic Automation: Community Developer Opportunities
DianaGray10
 
Make GenAI investments go further with the Dell AI Factory
Make GenAI investments go further with the Dell AI FactoryMake GenAI investments go further with the Dell AI Factory
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
The Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdfThe Changing Compliance Landscape in 2025.pdf
The Changing Compliance Landscape in 2025.pdf
Precisely
 
Play It Safe: Manage Security Risks - Google Certificate
Play It Safe: Manage Security Risks - Google CertificatePlay It Safe: Manage Security Risks - Google Certificate
Play It Safe: Manage Security Risks - Google Certificate
VICTOR MAESTRE RAMIREZ
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 

Java Programming - Conditional Statements (Switch).pdf

  • 1. 1 | 8 USING CONDITIONAL STATEMENTS: SWITCH STATEMENTS Java Programming – Using Conditional Statements: Switch Statements WHAT IS A CONDITIONAL STATEMENT? A conditional statement in Python programming is a type of statement that compares the values of two or more operands. An operand refers to the data that is used by the program either for comparison, manipulation, or mathematical operation. An operand can be: ▪ a value inputted by the user ▪ a value set by the programmer inside the program The results of the comparison using a conditional statement can result to either a TRUE or FALSE response. ▪ The TRUE response signifies that the values of operands are equal to one another or it is within the range provided by one of the operands. ▪ The FALSE response indicates that the values of operands are not equal to one another or it is outside the range provided by one of the operands. Programmers commonly use truth tables to determine whether the comparison between the data and the values set in the program will yield either a TRUE or FALSE response. The truth table is a visual representation that displays the inputted data, the set value, the argument, and the response. TRUTH TABLE Inputted Data Set Value Argument Response 8 5 8 > 5 True 20 20 20 != 20 False Yes Yes Yes == Yes True F f F == f False 25 15 25 >= 15 True In this lecture, we have to operands labelled as inputted data and set value. The “inputted data” refers to the data that was entered by the user in the program. The “set value” is the data that was specifically assigned in the program. The set value will serve as our basis for comparison that will check whether inputted data is equal to it or within its range. The “argument” is a statement that indicates how the operands are being compared to one another. Arguments in Python are expressed by using comparison operators. The comparison operators available in Python programming were as follows: COMPARISON OPERATOR DEFINITION SAMPLE STATEMENT == A comparison operator that checks if the operands are EQUAL to one another. a == b != A comparison operator that checks if the operands are NOT EQUAL to one another. a != b > A comparison operator that checks if value on the left side of the argument is GREATER THAN the value on the right side of the argument. a > b < A comparison operator that checks if value on the left side of the argument is LESS THAN the value on the right side of the argument. a < b >= A comparison operator that checks if value on the left side of the argument is GREATER THAN OR EQUAL TO the value on the right side of the argument. a >= b <= A comparison operator that checks if value on the left side of the argument is LESS THAN OR EQUAL TO the value on the right side of the argument. a <= b The “response” serves as the result of comparing the operands. The response can either be TRUE or FALSE based on the conditions that will determine whether the operands matches or does not match with one another.
  • 2. 2 | 8 USING CONDITIONAL STATEMENTS: SWITCH STATEMENTS Java Programming – Using Conditional Statements: Switch Statements PRACTICE WITH TRUTH TABLES Complete the table by filling up the Response Column with either TRUE or FALSE: TRUTH TABLE No. Inputted Data Set Value Argument Response 1 Rowell rowell Rowell == rowell 2 15 15 15 != 15 3 male Male male == Male 4 25 15 25 >= 15 5 1.3 4 1.3 <= 4 6 15 18 15 == 18 7 giraffe rhino giraffe == rhino 8 90 91 90 != 91 9 48 45 48 >= 45 10 107 92 107 < 92 USING SWITCH STATEMENT Now that we know how conditional statements work it is time for us to learn how to use one of the most basic form of conditional statements called switch statement. The switch statement is a type of conditional statement that is used to execute a block of code by comparing an operand to a specific value that was set in the program. The switch statement uses conditions that are labeled as cases. Each case is composed of the case, executable block of code and a break statement. Consider this example of a case: Case It refers to the statement that contains the condition. In the source code above, the line case “January”: details the condition where it asks if the operand presented to it is equal to January. Executable Block of Code The executable block of codes contains the instructions that the program will have to perform once the condition on the case matches the value of the operand. In our source code sample, the messages "The month is named after the Roman God, Janus." and "The presider of doors and beginnings." will be displayed on the screen if the operand is equal to January. If the operand fails to match the condition, the program will skip reading the executable block of code and jump directly to the next case. Break Statement The break statement indicates the end of the case. It signals the program to stop reading the next line of codes within the switch statement. If the program reached the line that contains the break; statement, the program will skip all other conditions and jump to the line of code that is outside the switch statement.
  • 3. 3 | 8 USING CONDITIONAL STATEMENTS: SWITCH STATEMENTS Java Programming – Using Conditional Statements: Switch Statements Sample Program 1: Create a Java program that will require the user to input any number from 1-3. The program will display an output statement based on these given conditions: ▪ If the user inputted number 1, it will display the sentence “You entered the number ONE.”. ▪ If the user inputted number 2, it will display the sentence “You entered the number TWO.”. ▪ If the user inputted number 3, it will display the sentence “You entered the number THREE.”. ▪ If the user inputted any number that is outside the range, it will display the sentence “The number you have entered is outside of the range given.”. Simulation of Program 1: USER’S INPUT PROGRAM’S OUTPUT 1 2 3 8 Source Code of Sample Program 1:
  • 4. 4 | 8 USING CONDITIONAL STATEMENTS: SWITCH STATEMENTS Java Programming – Using Conditional Statements: Switch Statements Let us examine the code: ▪ Line 1 contains the package name of our Java program named “switch_statement”. ▪ Line 2 is where we import the scanner in our program. In our previous sessions, we have learned that the scanner is a class in Java program that enables the program to get input from the user ▪ Line 4 contains the class name of our Java program named “Switch_Statement” while line 5 contains an open bracket ( { ) which indicates the beginning of the class. ▪ Line 7 contains the header of our main program while line 8 contains an open bracket ( { ) which indicates the beginning of the program body. ▪ On Line 9 we introduced our scanner to the program and assigned the name “mitis” to it. The new Scanner statement declares mitis as a new scanner in the program that takes in inputs from the user by using the System.in function. ▪ Line 10 is used to display message on the screen using the print ( ) function. The line explicitly instructed the program to show the message “Enter any number from 1-3” on the display screen. ▪ Line 11 displays the procedure that prepares the program to accept input from the user. The int num part of the statement declares the incoming input from the user as an integer (int) with the assigned name “num”. The mitis.nextInt( ) tells the program that the input will be captured using the scanner named mitis and that the input should be treated as an integer. ▪ Lines 12-26 details the procedure of using the switch statement.
  • 5. 5 | 8 USING CONDITIONAL STATEMENTS: SWITCH STATEMENTS Java Programming – Using Conditional Statements: Switch Statements • Line 12 displays the use of the function switch ( ). The identifier num that was enclosed in parentheses instructs the program that the value that was contained in num will be the value that will be used for the switch statement. The line 13 contains an open bracket ( { ) which indicates the beginning of the switch statement. • Line 14 contains the first condition of the program which checks if the value contained in num is equal to 1. If num is equal to one then the display message on line 15 will be shown on the screen. The line 16 contains the break statement which indicates the end of the first case. Note: If the value of num is not equal to 1, the program will skip reading lines 15 and 16 and automatically jumps to line 17. • Line 17 contains the second condition which checks if the value contained in num is equal to 2. If num is equal to two then the display message on line 18 will be shown on the screen. The line 19 contains the break statement which indicates the end of the second case. Note: If the value of num is not equal to 2, the program will skip reading lines 18 and 19 and automatically jumps to line 20. • Line 20 contains the third condition which checks if the value contained in num is equal to 3. If num is equal to three then the display message on line 21 will be shown on the screen. The line 22 contains the break statement which indicates the end of the third case. Note: If the value of num is not equal to 3, the program will skip reading lines 21 and 22 and automatically jumps to line 23. • Line 23 contains the default condition which accepts the input if it fails to match with any of the conditions written above it. If the program has reached this line of code it will automatically display the message on line 24. The line 22 contains the break statement which indicates the end of the default case. The line 26 contains an close bracket ( } ) which indicates the end of the switch statement.
  • 6. 6 | 8 USING CONDITIONAL STATEMENTS: SWITCH STATEMENTS Java Programming – Using Conditional Statements: Switch Statements Sample Program 2: Create a Java program that will require the user to choose an animal among the list of choices. The list of animals include dog, cat, bird, and fish. After the user have entered their choice of pet, the program will tell what personality do they have based on their chosen pet. ▪ If the user inputted dog, it will display the sentence “You have an outgoing personality.”. ▪ If the user inputted cat, it will display the sentence “You have a conservative personality.”. ▪ If the user inputted bird, it will display the sentence “You have caring personality.”. ▪ If the user inputted fish, it will display the sentence “You have a calm and stable personality.”. ▪ If the user inputted a name of an animal that is not included in the list, it will display the sentence “The animal you have entered is not in the list.”. Simulation of Program 2: USER’S INPUT PROGRAM’S OUTPUT dog cat bird fish chicken Source Code of Sample Program 2:
  • 7. 7 | 8 USING CONDITIONAL STATEMENTS: SWITCH STATEMENTS Java Programming – Using Conditional Statements: Switch Statements Programming Challenge 1: Create a Java program that will require the user to input a name of a country based on list of choices. The list includes Philippines, Japan, Korea, and China. After the user have entered their preferred country, the program will display the equivalent of “I love you” in the chosen language. ▪ If the user inputted Philippines, it will display the sentence “Mahal kita.”. ▪ If the user inputted Japan, it will display the sentence “Aishiteru”. ▪ If the user inputted Korea, it will display the sentence “Saranghaeyo.”. ▪ If the user inputted China, it will display the sentence “Wo ai ni”. ▪ If the user inputted a name of a country that is not included in the list, it will display the sentence “The country you have entered is not in the list.”. Simulation of Program 2: USER’S INPUT PROGRAM’S OUTPUT Philippines Japan Korea China Malaysia Programming Challenge 2: Create a Java program that will require the user to input any number from 1-12. The program will display the name of the month that corresponds to the user’s input. ▪ If the user inputted number 1, it will display the sentence “January is the 1st month of the year”. ▪ If the user inputted number 2, it will display the sentence “February is the 2nd month of the year”. ▪ If the user inputted number 3, it will display the sentence “March is the 3rd month of the year”. ▪ If the user inputted number 4, it will display the sentence “April is the 4th month of the year”. ▪ If the user inputted number 5, it will display the sentence “May is the 5th month of the year”. ▪ If the user inputted number 6, it will display the sentence “June is the 6th month of the year”. ▪ If the user inputted number 7, it will display the sentence “July is the 7th month of the year”. ▪ If the user inputted number 8, it will display the sentence “August is the 8th month of the year”. ▪ If the user inputted number 9, it will display the sentence “September is the 9th month of the year”. ▪ If the user inputted number 10, it will display the sentence “October is the 10th month of the year”. ▪ If the user inputted number 11, it will display the sentence “November is the 11th month of the year”. ▪ If the user inputted number 12, it will display the sentence “December is the 12th month of the year”. ▪ If the user inputted any number that is outside the range, it will display the sentence “Our calendar only has 12 months”. Simulation of Program 2: USER’S INPUT PROGRAM’S OUTPUT 1 2 45
  • 8. 8 | 8 USING CONDITIONAL STATEMENTS: SWITCH STATEMENTS Java Programming – Using Conditional Statements: Switch Statements