Switch Flashcards
The ________ in Java allows you to execute a specific block of code from various options, depending on the value of a variable or expressions. It serves as an alternative to multiple if-else statements, enhancing readability when handling a variable that can assume several distinct values.
switch statement
The switch statement in Java allows you to execute a specific ____________ from various options, depending on the value of a variable or expressions. It serves as an alternative to multiple if-else statements, enhancing readability when handling a variable that can assume several distinct values.
block of codes
_______ represent the values that the variable is compared against.
case labels
The switch statement in Java allows you to execute a specific block of code from various
_____, depending on the value of a variable or expressions. It serves as an alternative to
multiple if-else statements, enhancing readability when handling a variable that can assume
several distinct values.
options
The switch statement in Java allows you to execute a specific block of code from various
options, depending on the 1.____ of a 2._____ or 3.______. It serves as an alternative to
multiple if-else statements, enhancing readability when handling a variable that can assume
several distinct values.
1.value
2.variable
3.expressions
The switch statement in Java allows you to execute a specific block of code from various
options, depending on the value of a variable or expressions. It serves as an alternative to
multiple _______, enhancing readability when handling a variable that can assume
several distinct values.
if-else statements
The switch statement in Java allows you to execute a specific block of code from various
options, depending on the value of a variable or expressions. It serves as an alternative to
multiple if-else statements, enhancing 1._______ when handling a 2.______ that can assume
several distinct values.
1.readability
2.variable
Java provides two types of switch constructs:
- Switch Statements
2.Switch Expression
The traditional way to execute code of blocks based on a matched
case.
switch statements
Introduced in Java 12 (and standardized in Java 14). It allows the
switch to directly produce a value.
Switch Expression
Each type can use two style
- Colon Notation
- Arrow Notation
The older, classic format
Colon Notation
A newer, cleaner format introduced switch expression.
Arrow Notation
_______ is the ______ being tested.
variable
case labels represent the 1._____ that the 2._____ is compared against.
1.values
2.variable
The 1._______ is 2.____ but recommended, at it handles any cases explicitly covered by the
case labels
1.default case
2.optional
The default case is optional but _________, at it handles any cases explicitly covered by the
case labels
recommended
The default case is optional but recommended, at it handles any 1.____ explicitly covered by the
2._____
1.cases
2.case labels
The variable/expression in the switch must evaluate one of f the following types:
Int, type, short, char, String,, or enum.
Floating point numbers (float,double) are not allowed.
Expression Type
Expression Type:
The _________ in the switch must evaluate one f the following types;
Int, type, short, char, String,, or enum.
Floating point numbers (float,double) are not allowed.
variable/expression
Expression Type:
The variable/expression in the switch must evaluate one f the following types:
______________
Floating point numbers (float,double) are not allowed.
Int, type, short, char, String,, or enum.