Deck 3: Flow of Control

Full screen (f)
exit full mode
Question
A compound statement is enclosed between:
(a)[ ]
(b){ }
(c)( )
(d)< >
Use Space or
up arrow
down arrow
to flip the card.
Question
The looping mechanism that always executes at least once is the _____________ statement.
(a)if…else
(b)do…while
(c)while
(d)for
Question
In a switch statement,the default case is always executed.
Question
To compare two strings lexicographically the String method ____________ should be used.
(a)equals
(b)equalsIgnoreCase
(c)compareTo
(d)==
Question
Common loop errors are:
(a)Off-by-one
(b)Infinite loops
(c)Both a and b
(d)None of the above
Question
An if-else statement chooses between two alternative statements based on the value of a Boolean expression.
Question
You may omit the else part of an if-else statement if no alternative action is required.
Question
When the number of repetitions are known in advance,you should use a ___________ statement.
(a)while
(b)do…while
(c)for
(d)None of the above
Question
An if selection statement executes if and only if:
(a)the Boolean condition evaluates to false.
(b)the Boolean condition evaluates to true.
(c)the Boolean condition is short-circuited.
(d)none of the above.
Question
A mixture of programming language and human language is known as:
(a)Algorithms
(b)Recipes
(c)Directions
(d)Pseudocode
Question
The ____________ operator has the highest precedence.
(a)*
(b)dot
(c)+=
(d)decrement
Question
The controlling expression for a switch statement includes all of the following types except:
(a)char
(b)int
(c)byte
(d)double
Question
In a switch statement,the choice of which branch to execute is determined by an expression given in parentheses after the keyword switch.
Question
When using a compound Boolean expression joined by an && (AND)in an if statement:
(a)Both expressions must evaluate to true for the statement to execute.
(b)The first expression must evaluate to true and the second expression must evaluate to false for the statement to execute.
(c)The first expression must evaluate to false and the second expression must evaluate to true for the statement to execute.
(d)Both expressions must evaluate to false for the statement to execute.
Question
The OR operator in Java is represented by:
(a)!
(b)&&
(c)| |
(d)None of the above
Question
A ___________ statement terminates the current iteration of a loop.
(a)Break
(b)Continue
(c)Switch
(d)Assert
Question
To terminate a program,use the Java statement:
(a)System.quit(0);
(b)System.end(0);
(c)System.abort(0);
(d)System.exit(0);
Question
A multi-way if-else statement
(a)allows you to choose one course of action.
(b)always executes the else statement.
(c)allows you to choose among alternative courses of action.
(d)executes all Boolean conditions that evaluate to true.
Question
The association of operands with operators is called ______________.
(a)assignment
(b)precedence
(c)binding
(d)lexicographic ordering
Question
The negation operator in Java is represented by:
(a)!
(b)&&
(c)| |
(d)None of the above
Question
What output will be produced by the following code?
public class SelectionStatements
{
public static void main(String[] args)
{
int number = 24;
if(number % 2 == 0)
System.out.print("The condition evaluated to true!");
else
System.out.print("The condition evaluated to false!");
}
}
Question
When choosing a sentinel value,you should choose a value that would never be encountered in the input of the program.
Question
The three expressions at the start of a for statement are separated by two commas.
Question
Name and describe three types of branching mechanisms and give an example of each.
Question
Evaluate the Boolean equation: !( ( 6 < 5)&& (4 < 3))
Question
Discuss the rules Java follows when evaluating expressions.
Question
Write Java code that uses a for statement to sum the numbers from 1 through 50.Display the total sum to the console.
Question
What is a sentinel value and how is it used?
Question
What is short-circuit evaluation of Boolean expressions?
Question
Write an if-else statement to compute the amount of shipping due on an online sale.If the cost of the purchase is less than $20,the shipping cost is $5.99.If the cost of the purchase over $20 and at most $65,the shipping cost is $10.99.If the cost of the purchase is over $65,the shipping cost is $15.99.
Question
What would be the output of the code in #1 if number was originally initialized to 25?
Question
Not including the break statements within a switch statement results in a syntax error.
Question
Write a multi-way if-else statement that evaluates a persons weight on the following criteria: A weight less than 115 pounds,output: Eat 5 banana splits! A weight between 116 pounds and 130 pounds,output: Eat a banana split! A weight between 131 pounds and 200 pounds,output: Perfect! A weight greater than 200 pounds,output: Plenty of banana splits have been consumed!
Question
An algorithm is a step-by-step method of solution.
Question
Write Java code that uses a while loop to print even numbers from 2 through 10.
Question
The equality operator (==)may be used to test if two string objects contain the same value.
Question
An empty statement is defined as a loop that runs forever.
Question
The for statement,do…while statement and while statement are examples of branching mechanisms.
Question
Boolean expressions are used to control branch and loop statements.
Question
Write Java code that uses a do…while loop that prints even numbers from 2 through 10.
Question
What is the output of the following code segment?
public static void main(String[] args)
{
int x = 5;
System.out.println("The value of x is:" + x);
while(x > 0)
{
x++;
}
System.out.println("The value of x is:" + x);
}
Question
Discuss the differences between the break and the continue statements when used in looping mechanisms.
Question
Write a complete Java program that prompts the user for a series of numbers to determine the smallest value entered.Before the program terminates,display the smallest value.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/43
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 3: Flow of Control
1
A compound statement is enclosed between:
(a)[ ]
(b){ }
(c)( )
(d)< >
B
2
The looping mechanism that always executes at least once is the _____________ statement.
(a)if…else
(b)do…while
(c)while
(d)for
B
3
In a switch statement,the default case is always executed.
False
4
To compare two strings lexicographically the String method ____________ should be used.
(a)equals
(b)equalsIgnoreCase
(c)compareTo
(d)==
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
5
Common loop errors are:
(a)Off-by-one
(b)Infinite loops
(c)Both a and b
(d)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
6
An if-else statement chooses between two alternative statements based on the value of a Boolean expression.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
7
You may omit the else part of an if-else statement if no alternative action is required.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
8
When the number of repetitions are known in advance,you should use a ___________ statement.
(a)while
(b)do…while
(c)for
(d)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
9
An if selection statement executes if and only if:
(a)the Boolean condition evaluates to false.
(b)the Boolean condition evaluates to true.
(c)the Boolean condition is short-circuited.
(d)none of the above.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
10
A mixture of programming language and human language is known as:
(a)Algorithms
(b)Recipes
(c)Directions
(d)Pseudocode
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
11
The ____________ operator has the highest precedence.
(a)*
(b)dot
(c)+=
(d)decrement
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
12
The controlling expression for a switch statement includes all of the following types except:
(a)char
(b)int
(c)byte
(d)double
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
13
In a switch statement,the choice of which branch to execute is determined by an expression given in parentheses after the keyword switch.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
14
When using a compound Boolean expression joined by an && (AND)in an if statement:
(a)Both expressions must evaluate to true for the statement to execute.
(b)The first expression must evaluate to true and the second expression must evaluate to false for the statement to execute.
(c)The first expression must evaluate to false and the second expression must evaluate to true for the statement to execute.
(d)Both expressions must evaluate to false for the statement to execute.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
15
The OR operator in Java is represented by:
(a)!
(b)&&
(c)| |
(d)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
16
A ___________ statement terminates the current iteration of a loop.
(a)Break
(b)Continue
(c)Switch
(d)Assert
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
17
To terminate a program,use the Java statement:
(a)System.quit(0);
(b)System.end(0);
(c)System.abort(0);
(d)System.exit(0);
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
18
A multi-way if-else statement
(a)allows you to choose one course of action.
(b)always executes the else statement.
(c)allows you to choose among alternative courses of action.
(d)executes all Boolean conditions that evaluate to true.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
19
The association of operands with operators is called ______________.
(a)assignment
(b)precedence
(c)binding
(d)lexicographic ordering
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
20
The negation operator in Java is represented by:
(a)!
(b)&&
(c)| |
(d)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
21
What output will be produced by the following code?
public class SelectionStatements
{
public static void main(String[] args)
{
int number = 24;
if(number % 2 == 0)
System.out.print("The condition evaluated to true!");
else
System.out.print("The condition evaluated to false!");
}
}
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
22
When choosing a sentinel value,you should choose a value that would never be encountered in the input of the program.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
23
The three expressions at the start of a for statement are separated by two commas.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
24
Name and describe three types of branching mechanisms and give an example of each.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
25
Evaluate the Boolean equation: !( ( 6 < 5)&& (4 < 3))
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
26
Discuss the rules Java follows when evaluating expressions.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
27
Write Java code that uses a for statement to sum the numbers from 1 through 50.Display the total sum to the console.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
28
What is a sentinel value and how is it used?
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
29
What is short-circuit evaluation of Boolean expressions?
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
30
Write an if-else statement to compute the amount of shipping due on an online sale.If the cost of the purchase is less than $20,the shipping cost is $5.99.If the cost of the purchase over $20 and at most $65,the shipping cost is $10.99.If the cost of the purchase is over $65,the shipping cost is $15.99.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
31
What would be the output of the code in #1 if number was originally initialized to 25?
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
32
Not including the break statements within a switch statement results in a syntax error.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
33
Write a multi-way if-else statement that evaluates a persons weight on the following criteria: A weight less than 115 pounds,output: Eat 5 banana splits! A weight between 116 pounds and 130 pounds,output: Eat a banana split! A weight between 131 pounds and 200 pounds,output: Perfect! A weight greater than 200 pounds,output: Plenty of banana splits have been consumed!
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
34
An algorithm is a step-by-step method of solution.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
35
Write Java code that uses a while loop to print even numbers from 2 through 10.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
36
The equality operator (==)may be used to test if two string objects contain the same value.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
37
An empty statement is defined as a loop that runs forever.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
38
The for statement,do…while statement and while statement are examples of branching mechanisms.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
39
Boolean expressions are used to control branch and loop statements.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
40
Write Java code that uses a do…while loop that prints even numbers from 2 through 10.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
41
What is the output of the following code segment?
public static void main(String[] args)
{
int x = 5;
System.out.println("The value of x is:" + x);
while(x > 0)
{
x++;
}
System.out.println("The value of x is:" + x);
}
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
42
Discuss the differences between the break and the continue statements when used in looping mechanisms.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
43
Write a complete Java program that prompts the user for a series of numbers to determine the smallest value entered.Before the program terminates,display the smallest value.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 43 flashcards in this deck.