Switch Flashcards

1
Q

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.

A

switch statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A

block of codes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

_______ represent the values that the variable is compared against.

A

case labels

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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.

A

options

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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.

A

1.value
2.variable
3.expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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.

A

if-else statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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.

A

1.readability
2.variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Java provides two types of switch constructs:

A
  1. Switch Statements
    2.Switch Expression
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The traditional way to execute code of blocks based on a matched
case.

A

switch statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Introduced in Java 12 (and standardized in Java 14). It allows the
switch to directly produce a value.

A

Switch Expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Each type can use two style

A
  1. Colon Notation
  2. Arrow Notation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The older, classic format

A

Colon Notation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A newer, cleaner format introduced switch expression.

A

Arrow Notation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

_______ is the ______ being tested.

A

variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

case labels represent the 1._____ that the 2._____ is compared against.

A

1.values
2.variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The 1._______ is 2.____ but recommended, at it handles any cases explicitly covered by the
case labels

A

1.default case
2.optional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The default case is optional but _________, at it handles any cases explicitly covered by the
case labels

A

recommended

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

The default case is optional but recommended, at it handles any 1.____ explicitly covered by the
2._____

A

1.cases
2.case labels

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

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.

A

Expression Type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

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.

A

variable/expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Expression Type:

The variable/expression in the switch must evaluate one f the following types:
______________
Floating point numbers (float,double) are not allowed.

A

Int, type, short, char, String,, or enum.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Expression Type:

The variable/expression in the switch must evaluate one f the following types;
Int, type, short, char, String,, or enum.
____________ are not allowed.

A

Floating point numbers (float,double)

23
Q

No duplicate value are allowed across case labels. Each case ends with a break (optional but recommended) to prevent “fall-through.”

A

Case Labels

24
Q

Case Label: No ______ are allowed across case labels:
Each case ends with a break (optional but recommended) to prevent “fall-through.”

A

duplicate value

25
Q

Case Labels: No duplicate value are allowed across case labels:

Each case ends with a break (optional but recommended) to prevent ______.

A

fall-through

26
Q

Each case ends with a _____ (optional but recommended) to prevent ______.

A

break

27
Q

Each case ends with a break (______ but recommended) to prevent fall-through

A

optional

28
Q

Case Labels: No duplicate value are allowed across ______:

A

case labels

29
Q

You can’t use a 1______ or 2._____ because the 3._______ needs to know exactly what to 4._____ when the 5._____ runs.

A

1.variable
2.calculation
3.computer
4.match
5.program

30
Q

Each case value must be a 1.______ or a 2.____, not a 3._____ or 4._____. In switch statements, each case must have a fixed value that doesn’t change, like a number, a word, or a character.

A

1.constant
2.literal
3.variable
4.expression

31
Q

Each case value must be a constant or a literal, not a variable or expression. In 1.______, each 2.____ must have a 3.____ that doesn’t change, like a number, a word, or a character.

A
  1. switch statements
    2.case
    3.fixed value
32
Q

Each case value must be a constant or a literal, not a variable or expression. In switch statements, each case must have a fixed value that doesn’t change, like a 1._____, a 2.____, or a _______.

A

1.number
2.word
3.character

33
Q

The default label is optional but is used to handle unexpected values.If no case matches and there’s no default, the program continues after the switch.

A

Default Case

34
Q

The 1._____ is 2.____ but is used to handle 3.______If no case matches and there’s no default, the program continues after the switch.

A

1.default label
2.optional
3.unexpected values

35
Q

The break exits the switch block. Omitting a break will cause all subsequent case blocks to execute until a break is found(fall-through behavior).

A

Break Statement

36
Q

The break exits the switch block. Omitting a break will cause all 1._______ to execute until a break is found 2._____

A

1.subsequent case blocks
2.(fall-through behavior).

37
Q

A 1.______ can include any number of case labels, followed by the 2._______. A crucial aspect of writing a switch statement in Java is the 3.______.Without a break, the program will continue executing the following cases, even if they don’t match the condition– a phenomenon known as ‘4._____.” Including a break ensures that the program exits the 5.______ after a matching case is executed.

A

1.switch block
2.code block to execute
3.break statement
4.fall-through
5.switch statement

38
Q

Including a break ensures that the program 1.____ the 2._____ after a 3.____ is 4._____.

A

1.exits
2.switch statement
3.matching case
4. executed

39
Q

1._______: In scenarios with multiple conditions, switch statements can be more 2.____ than their 3._____. By utilizing a switch statement, the computer can 4._____” to the appropriate case, potentially employing an efficient 5._____, such as a shortcut list or a rapid search.

A

1.Efficiency
2.efficient
3.if-else counterparts
4.swiftly”jump
5.internal method

40
Q

This approach can lead to 1._____ than evaluating condition 2._______, as is done with 3.______.

A

1.faster performance
2.sequentially
3.if-else statements

41
Q

By utilizing a switch statement, the computer can swiftly”jump” to the appropriate case, potentially employing an efficient internal method, such as a 1.______ or a 2.___.

A

1.shortcut list
2.rapid search

42
Q

1.______: Switch statements can make 2._______clearer and more straightforward, making your code easier to read and maintain.

A

1.Readability
2.complex conditional logic

43
Q

Readability: Switch statements can make complex conditional logic 1.____ and 2._____, making your code 3.____ to 4.___ and 5._____.

A

1.clearer
2.more straightforward
3.easier
4.read
5.maintain

44
Q

1.____: Writing a switch statement often requires 2.____ than a 3._____ of 4._____, making your 5._____ and 6.______.

A

1.Simplicity
2.less syntax
3.comparable series
4.if-else statements
5.code simpler
6.more concise

45
Q

In Java, 1.____ is a 2.____ introduced as part of 3.______ in 4._____ (as a preview feature) and officially released in 5.____.

A

1.yield
2.keyword
3.switch expressions
4.Java 13
5.Java 14

46
Q

The 1._______ allows you to 2.______ from a 3._____ when 4._______ are required for a particular case. This is different from the -> arrow notation, which allows a direct return,and provides more flexibility in cases where complex logic is necessary.

A

1.yield keyword
2.return a value
3.switch expression
4.multiple lines of code

47
Q

This is different from the -> arrow notation, which allows a 1._____,and provides more 2.____ in cases where 3._____ is 4.____.

A

1.direct return
2.flexibility
3.complex logic
4.necessary

48
Q

Before yield, 1._______ with 2._____ were limited to 3.______. However, if you needed to perform more than one operator in case (e.g.,calculations, logging, or complex decision-making), yield enables you to do so while still returning a value from the switch expression.

A

1.switch expressions
2.arrow notation
3.simple one-liner operations

49
Q

Before yield, switch expressions with arrow notation were limited to simple one-lineroperations. However, if you needed to perform 1.______ in case (2.______, 3._____, or 4.______), yield enables you to do so while still returning a value from the switch expression.

A

1.more than one operator
2.e.g.,calculations
3.logging
4.complex decision-making

50
Q

1.____ enables you to do so while still 2._______ from the 3._____.

A

1.yield
2.returning a value
3.switch expression

51
Q

1.______ is used to 2._____ from a 3._____ in a 4.____:

A

1.Yield
2.return a value
3.case block
4.switch expression

52
Q

The ______ is applied to remove any unwanted spaces that may beaccidentally entered before or after the day case.

A

trim() method

53
Q

The trim() method is applied to 1.____ any 2._____ that may be accidentally entered before or after the day case.

A

1.remove
2.unwanted spaces