Week 9 Part 2 Flashcards

1
Q

o “else” vs. “else if” at end of an if statement, what is the difference in behaviour?

A

o “else” at the end of an if statement means that one of the expressions will run, no matter what. With “else if” an if condition must be true before anything executes.

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

o T/F – Else can be used by itself.

A

False

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

o T/F – You can nest if in if-else selection structures.

A

True

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

o Java coding conventions – an if statement must be indented _ tab or _ spaces

A

1 tab, 4 spaces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  • Problems with if that are really hard to debug
A

Forgetting to use {braces}.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  • What logic error can occur if you forget to add braces to your if statement and there are 2 subsequent statements?
A

o 1 statement is run rather than 2, and the 2nd one is interpreted as a regular line of code
o This can be hard to catch as the 2nd line will likely also be indented

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  • What does a semicolon do in an if structure?
A

o It ends the if structure, causing subsequent lines to always execute

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

o hasNextInt() and hasNextDouble() return_______ data types and are used for

A

 Boolean, User input data validation

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

o Compares the value provided in the (brackets) with each case until it finds a match or exits the structure

A
  • Java switch structure (case structure)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

o T/F – All case structures must have a default option

A

False.

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

o When a case is matched in a switch structure, the statements under it are executed until a ____ statement

A

 Break

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

o If the break is omitted from a switch case, what happens?

A

 The program begins executing case statements that are underneath the entered case

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

o Each case in a case structure must have a _______ _____, no variables. Constants are okay.

A

 Literal value

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

o Per common practice, default is usually placed at the ___ of the case structure

A

End

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

o T/F – You can nest a switch inside of an if, and vice versa

A

True

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

o A variable declared in an if, else, or switch is limited to the _______ it was declared in

A

{block}

17
Q

o What type of operator is the conditional operator?

A

 Ternary

18
Q

o Ternary means

A

 3 operands

19
Q

o Allows for a decision to be made, and then a value return, all in one line

A

 Conditional operator