Deck 3: Flow of Control

Full screen (f)
exit full mode
Question
To compare two strings lexicographically the String method ____________ should be used.

A)equals
B)equalsIgnoreCase
C)compareTo
D)==
Use Space or
up arrow
down arrow
to flip the card.
Question
The association of operands with operators is called ______________.

A)assignment
B)precedence
C)binding
D)lexicographic ordering
Question
To terminate a program,use the Java statement:

A)System.quit0);
B)System.end0);
C)System.abort0);
D)System.exit0);
Question
A ___________ statement terminates the current iteration of a loop.

A)Break
B)Continue
C)Switch
D)Assert
Question
The ____________ operator has the highest precedence.

A)*
B)dot
C)+=
D)decrement
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
The controlling expression for a switch statement includes all of the following types except:

A)char
B)int
C)byte
D)double
Question
The OR operator in Java is represented by:

A)!
B)&&
C)| |
D)None of the above
Question
The negation operator in Java is represented by:

A)!
B)&&
C)| |
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
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
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
An if-else statement chooses between two alternative statements based on the value of a Boolean expression.
Question
A compound statement is enclosed between:

A)[ ]
B){ }
C))
D)< >
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
Common loop errors are:

A)Off-by-one
B)Infinite loops
C)Both a and b
D)None of the above
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 looping mechanism that always executes at least once is the _____________ statement.

A)if…else
B)do…while
C)while
D)for
Question
Good debugging techniques include:

A)Inserting output statements in your program.
B)Tracing variables
C)Using an IDE debugger
D)All of the above
Question
What is a sentinel value and how is it used?
Question
The three expressions at the start of a for statement are separated by two commas.
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
What output will be produced by the following code?
public class SelectionStatements
{
public static void mainString[] args)
{
int number = 24;
ifnumber % 2 == 0)
System.out.print"The condition evaluated to true!");
else
System.out.print"The condition evaluated to false!");
}
}
Question
An algorithm is a step-by-step method of solution.
Question
Evaluate the Boolean equation: ! 6 < 5)&& 4 < 3))
Question
Boolean expressions are used to control branch and loop statements.
Question
The equality operator ==)may be used to test if two string objects contain the same value.
Question
What would be the output of the code in #1 if number was originally initialized to 25?
Question
An empty statement is defined as a loop that runs forever.
Question
Write Java code that uses a while loop to print even numbers from 2 through 10.
Question
The for statement,do…while statement and while statement are examples of branching mechanisms.
Question
Name and describe three types of branching mechanisms and give an example of each.
Question
Not including the break statements within a switch statement results in a syntax error.
Question
When choosing a sentinel value,you should choose a value that would never be encountered in the input of the program.
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
In a switch statement,the default case is always executed.
Question
Write Java code that uses a do…while loop that prints even numbers from 2 through 10.
Question
Discuss the rules Java follows when evaluating expressions.
Question
What is short-circuit evaluation of Boolean expressions?
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.
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
Discuss the differences between the break and the continue statements when used in looping mechanisms.
Question
What is the output of the following code segment?
public static void mainString[] args)
{
int x = 5;
System.out.println"The value of x is:" + x);
whilex > 0)
{
x++;
}
System.out.println"The value of x is:" + x);
}
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/44
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 3: Flow of Control
1
To compare two strings lexicographically the String method ____________ should be used.

A)equals
B)equalsIgnoreCase
C)compareTo
D)==
C
2
The association of operands with operators is called ______________.

A)assignment
B)precedence
C)binding
D)lexicographic ordering
C
3
To terminate a program,use the Java statement:

A)System.quit0);
B)System.end0);
C)System.abort0);
D)System.exit0);
D
4
A ___________ statement terminates the current iteration of a loop.

A)Break
B)Continue
C)Switch
D)Assert
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
5
The ____________ operator has the highest precedence.

A)*
B)dot
C)+=
D)decrement
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
6
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 44 flashcards in this deck.
Unlock Deck
k this deck
7
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 44 flashcards in this deck.
Unlock Deck
k this deck
8
The OR operator in Java is represented by:

A)!
B)&&
C)| |
D)None of the above
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
9
The negation operator in Java is represented by:

A)!
B)&&
C)| |
D)None of the above
Unlock Deck
Unlock for access to all 44 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 44 flashcards in this deck.
Unlock Deck
k this deck
11
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 44 flashcards in this deck.
Unlock Deck
k this deck
12
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 44 flashcards in this deck.
Unlock Deck
k this deck
13
An if-else statement chooses between two alternative statements based on the value of a Boolean expression.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
14
A compound statement is enclosed between:

A)[ ]
B){ }
C))
D)< >
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
15
You may omit the else part of an if-else statement if no alternative action is required.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
16
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 44 flashcards in this deck.
Unlock Deck
k this deck
17
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 44 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 44 flashcards in this deck.
Unlock Deck
k this deck
19
The looping mechanism that always executes at least once is the _____________ statement.

A)if…else
B)do…while
C)while
D)for
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
20
Good debugging techniques include:

A)Inserting output statements in your program.
B)Tracing variables
C)Using an IDE debugger
D)All of the above
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
21
What is a sentinel value and how is it used?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
22
The three expressions at the start of a for statement are separated by two commas.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
23
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 44 flashcards in this deck.
Unlock Deck
k this deck
24
What output will be produced by the following code?
public class SelectionStatements
{
public static void mainString[] args)
{
int number = 24;
ifnumber % 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 44 flashcards in this deck.
Unlock Deck
k this deck
25
An algorithm is a step-by-step method of solution.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
26
Evaluate the Boolean equation: ! 6 < 5)&& 4 < 3))
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
27
Boolean expressions are used to control branch and loop statements.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
28
The equality operator ==)may be used to test if two string objects contain the same value.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
29
What would be the output of the code in #1 if number was originally initialized to 25?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
30
An empty statement is defined as a loop that runs forever.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
31
Write Java code that uses a while loop to print even numbers from 2 through 10.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
32
The for statement,do…while statement and while statement are examples of branching mechanisms.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
33
Name and describe three types of branching mechanisms and give an example of each.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
34
Not including the break statements within a switch statement results in a syntax error.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
35
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 44 flashcards in this deck.
Unlock Deck
k this deck
36
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 44 flashcards in this deck.
Unlock Deck
k this deck
37
In a switch statement,the default case is always executed.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
38
Write Java code that uses a do…while loop that prints even numbers from 2 through 10.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
39
Discuss the rules Java follows when evaluating expressions.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
40
What is short-circuit evaluation of Boolean expressions?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
41
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 44 flashcards in this deck.
Unlock Deck
k this deck
42
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 44 flashcards in this deck.
Unlock Deck
k this deck
43
Discuss the differences between the break and the continue statements when used in looping mechanisms.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
44
What is the output of the following code segment?
public static void mainString[] args)
{
int x = 5;
System.out.println"The value of x is:" + x);
whilex > 0)
{
x++;
}
System.out.println"The value of x is:" + x);
}
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 44 flashcards in this deck.