Module 2 (Prelim) Flashcards
2.1 Overview 2.2 Relational and Logical Expressions 2.3 Arithmetic Assignment Operator 2.4 The if and if...else Statements 2.5 Nested if and else…if statements 2.6 switch Statement
allows a program to make a decision based on the truth or falsity of some statement of fact
condition
________ in if structures are formed by using the relational operators and logical operators.
Conditions
________ and ________ operators are binary operators (except !) and yield either true or false boolean value.
- Relational
- logical
Types of relational operators: (6)
==
!=
<
<=
>
>=
Types of logical operators (in order): (3)
!
&&
||
Relational operators are higher than logical operators (&&, ||)
(True or False)
T
Relational operators:
Equality operators (==, !=) are higher than comparison operators (<, >, <=, >=)
F
Unary operators (ex. ! ) has the highest order of precedence
T
Arrange the ff operator types from highest to lowest:
Arithmetic
Unary
Ternary
Relational
Assignment
Bitwise
Logical
Unary (~, !)
Arithmetic (*, /, %, and +, -)
Relational (<, >, <=, >=, and ==, !=)
Bitwise (&, ^, |)
Logical (&& and ||)
Ternary (? and :)
Assignment (=, +=, -= , etc.)
Repeatedly increasing a value by some amount
Accumulating
Java provides shortcuts for incrementing and accumulating such as: (5)
*=
/=
%=
( arithmetic operators + (=) assign operator)
the associativity of ! is from left-to-right
(True or False)
F
right-to-left
In Java, when you want to take an action if a Boolean expression is true, you use an ________ statement.
if
If you want to take an action when a Boolean expression is true but take a different action when the expression is false, you use an ________ statement.
if…else
if and if…else statements can be used to create:
One-way selection
Two-way selection
Multiple selections
if statement one-way selection syntax:
if (expression)
….statement
if and if…else will only apply the first statement below the condition.
(True or False)
T
unless the programmer uses a { } for multiple commands
if…else statement w/ multiple statements/compound statements syntax:
if (expression)
{
….statement1
….statement2
}
else
{
….statement1
….statement2
}
if…else statement two-way selection syntax:
if (expression)
….statement1
else
….statement2
There are statements in which an if structure is contained inside another if structure
Nested if
Two conditions must be met before some action is taken
Nested if
Uses the else if statement to specify a new condition if the first condition is false
Nested else…if
Nested if syntax:
if (condition1)
….if (condition2)
……..statement1;
Nested else…if syntax:
if (condition1)
….statement1;
else if (condition2)
….statement2;
else if (condition3)
….statement3;
else
….statement n;
_________ operator takes 3 arguments
ternary
Ternary operator syntax:
expression1 ? expression2 : expression3
(this means that If expression1 is true, the result of the conditional expression is expression2. Otherwise, the result is expression3)
An alternative to a series of nested if statements
Switch statements
Test a single variable against a series of exact integer, character, or string values
Switch statements
Switch statement keywords: (4)
- switch
- case
- break
- default
Starts the switch structure followed by a test expression enclosed in parentheses
switch
Followed by one of the possible values for the test expression and a colon. Braces are not needed to turn multiple statements into a single compound statement
case
In a switch statement when a case value is matched, all statements after it execute until a ______ is encountered
break
The break statement may or may not appear after each statement in switch statements
(True or False)
T
Switch statement:
Optionally ________ is used prior to any action that should occur if the test variable does not match any case
default
There are two types of algorithm:
Pseudocode
Flowchart
Plan a program’s logic by writing plain English statements
Pseudocode
- Steps in diagram form
- A series of shapes connected by arrows
Flowchart
The six (6) basic flowcharting symbols are:
- Terminator ⬭
- Input/Output ▱
- Process ▭
- Decision ◇
- Connector ◯
- Flowline / arrows →
used to represent the start and end of a flowchart
Terminator ⬭
used for input and output decisions in a flowchart
Input/Output ▱
used for arithmetic and data manipulation operations in a flowchart
Process ▭
used for logic of comparison operations in a flowchart
Decision ◇
Used to join two different flowlines in a flowchart
Connector ◯
Used to connect symbols and indicate the flow of logic of a flowchart
Flowline / arrows →