Intro to programming UNIT 3 Flashcards
What is a ternary operator
The ternary operator is a short if else statement in one line. It takes three operands
What operands does a ternary operator take. In what order
- The condition being tested
- Value if true
- Value if false
ex:
condition ? value if true : value if false
What does the && operator do and what is it’s logical table?
The && Operator is for logical AND. Both operands need to be true for it to return as TRUE
side 1 side 2 result
false false false
true false false
false true false
true true true
What does the || operator do and what’s it logic table
The || Operator is for logical OR. Either or both operands need to be true for it to return as TRUE
side 1 side 2 result
false false false
true false true
false true true
true true true
What is the logical not operator?
Using the (!) exlamation mark
How do you invert the && or the || operator?
You add the exclamation mark before
ex:
!||
!&&
What is called an inverse of an or?
NOR or NOT OR
What is the inverse of an and
NAND
What is the Logical XOR or Exclusive OR or Bitwise comparison operator?
Using the caret or ^ symbol
What is the XOR operator truth table?
Both sides cannot be the same for the operator to return as true
false false false
true false true
false true true
true true false
What is the XOR of
0001
0011
Result 0010
What evaluations can you use in a SWITCH statement
You can only use equality operators in a switch evaluation. Therefore you cannot use > < operators only ==
What’s the structure of a switch statement?
switch(toBeEvaluated) {
case 1:
break;
What is default for a switch?
Default is the case that will be run if no matches are found. It needs to be placed at the bottom of the switch case
What is a TRAILING ELSE BLOCK
It’s the default case that executes if none of the other cases evaluate to true
What is range testing?
It’s the testing of a value to see if it fits between set constraints
What operator does the inside the fence check use?
It uses the AND Operator
What operator does the outside the fence check use?
It uses the OR Operator
What datatypes can be evaluated in a switch statement
It can only be used with items that can be compared for equality. Therefore you cannot evaluate doubles, floats and items that are not whole.
What datatypes can you use in a switch
Int
Char
Strings
What isn’t required in a default switch case?
You do not need a break statement. Since it will already be the last case to be evaluated.
What happens when you compare Object with the “==” equality operator
It checks to see if it’s the same object. It will not necessarily check the data in them. Ex: Comparing string objects
How do you compare string objects?
stringOne.equals(stringTwo);
This will return a boolean value. If both char arrays match it will return true. False if not matching.