Chapter 5 PDF Flashcards
Describe sequence in the flow of control
Execute instructions in order
Describe method calls in the flow of control
Transfer control to method, execute instructions in method, then return with or without a value
Describe selection in the flow of control
Execute different instructions depending on the data
Describe looping in the flow of control
Repeat a set of instructions for different data
Describe equality operators
They’re used to determine if the values of two expressions are equal or not equal
What is special about equality operators
Must be used with a primitive data type and object references, not to compare object data
What is a common error made with equality operators
Equality operators (==) and easily confused with the assignment operator (=)
What is relational operators used for
Relational Operators are used to compare the values of two expressions
What is the result for relational operators
The result for relational operators is either true or false
What is ! used for in programming
! is the NOT operator
What is the ! (NOT OPERATOR) used for
The NOT operator is used to evaluate to the inverse of the value of its operand. (EX: If the operand is true the result will be the opposite)
What is && used for in programming
&& is the AND operator
What is the && (AND OPERATOR) used for
The AND operator takes two boolean expressions as operands, if both operands are true then the result is true. Otherwise the result is false.
What is || used for in programming
|| is the OR operator
What is the OR operator used for
The OR operator takes two boolean expressions as operands. If both operands are false, the result will be false and otherwise it’ll be true.
In any logical operator, how are the operands evaluated?
Operands are evaluated left to right for any logical operator
What occurs if the result of the logical operator can be determined after evaluating the first operand
Only the first operand will be evaluated and the second one will be ignored
What is the result if the first operand of an OR statement is true
The result of the statement will be TRUE
What is the result if the first operand of an AND statement is false
The result of the statement will be FALSE
What is a common error when testing three ints
Each operand of a logical operator must be a boolean expression or else you will have a compiler error
What are DeMorgans Laws
- NOT( A AND B ) = ( NOT A ) OR ( NOT B )
2. NOT( A OR B ) = ( NOT A ) AND ( NOT B )
How would you find an equivalent expression using DeMorgans Laws
- Change AND to OR
- Change OR to AND
- NEGATE EACH OPERAND EXPRESSION