Deck 4: Decision Structures
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/42
Play
Full screen (f)
Deck 4: Decision Structures
1
Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2?
A) str1.equalsIgnoreCase(str2)
B) str1.equalsInsensitive(str2)
C) str1 != str2
D) str1 || str2
A) str1.equalsIgnoreCase(str2)
B) str1.equalsInsensitive(str2)
C) str1 != str2
D) str1 || str2
A
2
When testing for character values, the switch statement does not test for the case of the character.
False
3
The DecimalFormat class is part of the Java API so it is automatically available to your programs.
False
4
The boolean expression in an if statement must evaluate to
A) degrees or radians
B) true or false
C) positive or negative
D) left or right
A) degrees or radians
B) true or false
C) positive or negative
D) left or right
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
5
__________ operators are used to determine whether a specific relationship exists between two values.
A) Assignment
B) Arithmetic
C) Logical
D) Relational
A) Assignment
B) Arithmetic
C) Logical
D) Relational
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
6
In an if-else statement, if the boolean expression is false
A) no statements or blocks are executed
B) the statement or block following the else is executed
C) the first statement or block is executed
D) all the statements or blocks are executed
A) no statements or blocks are executed
B) the statement or block following the else is executed
C) the first statement or block is executed
D) all the statements or blocks are executed
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
7
All it takes for an AND expression to be true is for one of the subexpressions to be true.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
8
A flag may have the values
A) defined or undefined
B) true or false
C) of any range of integers
D) of any Unicode character
A) defined or undefined
B) true or false
C) of any range of integers
D) of any Unicode character
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
9
Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8?
A) "###.#"
B) "###.0"
C) "000.0"
D) "#0.00%"
A) "###.#"
B) "###.0"
C) "000.0"
D) "#0.00%"
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
10
A block of code is enclosed in a set of
A) braces, { }
B) parentheses, ( )
C) brackets, [ ]
D) double quotes, " "
A) braces, { }
B) parentheses, ( )
C) brackets, [ ]
D) double quotes, " "
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
11
If the expression on the left side of the && operator is false, the expression on the right side will not be checked.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
12
Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8%?
A) "##0.0%"
B) "###.##%"
C) "000.0%"
D) "#0.00%"
A) "##0.0%"
B) "###.##%"
C) "000.0%"
D) "#0.00%"
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
13
When two strings are compared using the String class's compareTo method, the comparison is not case sensitive.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
14
Unicode is an international encoding system that is extensive enough to represent all the characters of all the world's alphabets.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
15
A random number, created as an object of the Random class, is always an integer.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
16
In a switch statement, if two different values for the CaseExpression would result in the same code being executed, you must have two copies of the code, one after each CaseExpression.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
17
All it takes for an OR expression to be true is for one of the subexpressions to be true.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
18
An important style rule that should be used when writing if statements is to write the conditionally executed statement on the line after the if statement.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
19
If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?
A) str1 = str2
B) str1 && str2
C) str1.equals(str2)
D) str1 += str2
A) str1 = str2
B) str1 && str2
C) str1.equals(str2)
D) str1 += str2
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
20
The if-else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following expressions will generate a random number in the range of 1 through 10?
A) myNumber = randomNumbers.nextInt(10);
B) myNumber = randomNumbers.nextInt(1) + 10;
C) myNumber = randomNumbers.nextInt(11) - 1;
D) myNumber = randomNumbers.nextInt(10) + 1;
A) myNumber = randomNumbers.nextInt(10);
B) myNumber = randomNumbers.nextInt(1) + 10;
C) myNumber = randomNumbers.nextInt(11) - 1;
D) myNumber = randomNumbers.nextInt(10) + 1;
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
22
What will be the value of x after the following statements are executed?
int x = 75;
Int y = 60;
If (x > y)
X = x - y;
A) 60
B) 75
C) 15
D) 135
int x = 75;
Int y = 60;
If (x > y)
X = x - y;
A) 60
B) 75
C) 15
D) 135
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
23
What will be displayed after the following statements are executed?
int x = 65;
Int y = 55;
If (x >= y)
{
Int ans = x + y;
}
System.out.println(ans);
A) 10
B) 120
C) 100
D) The code contains an error and will not compile.
int x = 65;
Int y = 55;
If (x >= y)
{
Int ans = x + y;
}
System.out.println(ans);
A) 10
B) 120
C) 100
D) The code contains an error and will not compile.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
24
What will be the values of ans, x, and y after the following statements are executed?
int ans = 35, x = 50, y = 50;
If (x >= y)
{
Ans = x + 10;
X -= y;
}
Else
{
Ans = y + 10;
Y += x;
}
A) ans = 60, x = 0, and y = 50
B) ans = 45, x = 50, and y = 0
C) ans = 45, x = 50, and y = 50
D) ans = 60, x = 50, and y = 100
int ans = 35, x = 50, y = 50;
If (x >= y)
{
Ans = x + 10;
X -= y;
}
Else
{
Ans = y + 10;
Y += x;
}
A) ans = 60, x = 0, and y = 50
B) ans = 45, x = 50, and y = 0
C) ans = 45, x = 50, and y = 50
D) ans = 60, x = 50, and y = 100
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
25
What will be the value of ans after the following statements are executed?
int x = 40;
Int y = 40;
If (x = y)
Ans = x + 10;
A) 30
B) 80
C) 50
D) The code contains an error and will not compile.
int x = 40;
Int y = 40;
If (x = y)
Ans = x + 10;
A) 30
B) 80
C) 50
D) The code contains an error and will not compile.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
26
The __________ statement is used to create a decision structure which allows a program to have more than one path of execution.
A) block
B) if
C) null
D) flag
A) block
B) if
C) null
D) flag
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
27
A __________ is a boolean variable that signals when some condition exists in the program.
A) sentinel
B) flag
C) block
D) case
A) sentinel
B) flag
C) block
D) case
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
28
Which of the following statements determines whether the variable temp is within the range of 0 through 100 (inclusive)?
A) if (temp >= 0 && temp <= 100)
B) if (temp > 0 && temp < 100)
C) if (temp >= 0 || temp <= 100)
D) if (temp > 0 || temp < 100)
A) if (temp >= 0 && temp <= 100)
B) if (temp > 0 && temp < 100)
C) if (temp >= 0 || temp <= 100)
D) if (temp > 0 || temp < 100)
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
29
What will be displayed after the following statements are executed?
int hours = 30;
Double pay, payRate = 10.00;
Pay = hours <= 40 ? hours*payRate : hours*payRate*2.0;
System.out.println(pay);
A) 300.0
B) 600.0
C) 400.0
D) The code contains an error and will not compile.
int hours = 30;
Double pay, payRate = 10.00;
Pay = hours <= 40 ? hours*payRate : hours*payRate*2.0;
System.out.println(pay);
A) 300.0
B) 600.0
C) 400.0
D) The code contains an error and will not compile.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
30
Enclosing a group of statements inside a set of braces creates
A) an expression
B) a block of statements
C) a relational operator
D) a conditional statement
A) an expression
B) a block of statements
C) a relational operator
D) a conditional statement
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following expressions determines whether the char variable, chrA, is not equal to the letter 'A'?
A) chrA == 'A'
B) chrA != 'A'
C) chrA || 'A'
D) chrA.notEquals(A)
A) chrA == 'A'
B) chrA != 'A'
C) chrA || 'A'
D) chrA.notEquals(A)
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
32
Java requires that the boolean expression being tested by an if statement be enclosed in
A) a set of parentheses
B) a set of braces
C) a set of double quotes
D) a set of brackets
A) a set of parentheses
B) a set of braces
C) a set of double quotes
D) a set of brackets
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
33
What will be the value of discountRate after the following statements are executed?
double discountRate;
Char custType = 'B';
Switch (custType)
{
Case 'A':
DiscountRate = 0.08;
Break;
Case 'B':
DiscountRate = 0.06;
Case 'C':
DiscountRate = 0.04;
Default:
DiscountRate = 0.0;
}
A) 0.08
B) 0.06
C) 0.04
D) 0.0
double discountRate;
Char custType = 'B';
Switch (custType)
{
Case 'A':
DiscountRate = 0.08;
Break;
Case 'B':
DiscountRate = 0.06;
Case 'C':
DiscountRate = 0.04;
Default:
DiscountRate = 0.0;
}
A) 0.08
B) 0.06
C) 0.04
D) 0.0
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
34
What will be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
Int purchase = 100;
If (purchase > 1000)
DiscountRate = 0.05;
Else if (purchase > 750)
DiscountRate = 0.03;
Else if (purchase > 500)
DiscountRate = 0.01;
A) 0.0
B) 0.05
C) 0.03
D) 0.01
double discountRate = 0.0;
Int purchase = 100;
If (purchase > 1000)
DiscountRate = 0.05;
Else if (purchase > 750)
DiscountRate = 0.03;
Else if (purchase > 500)
DiscountRate = 0.01;
A) 0.0
B) 0.05
C) 0.03
D) 0.01
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
35
When a character is stored in memory, it is actually the __________ that is stored.
A) Unicode number
B) ASCII code
C) floating-point value
D) letter, symbol, or number
A) Unicode number
B) ASCII code
C) floating-point value
D) letter, symbol, or number
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
36
Which of the following expressions will determine whether x is less than or equal to y?
A) x <= y
B) x => y
C) x >= y
D) x =< y
A) x <= y
B) x => y
C) x >= y
D) x =< y
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
37
What will be the value of bonus after the following statements are executed? int bonus, sales = 10000;
If (sales < 5000)
Bonus = 200;
Else if (sales < 7500)
Bonus = 500;
Else if (sales < 10000)
Bonus = 750;
Else if (sales < 20000)
Bonus = 1000;
Else
Bonus = 1250;
A) 750
B) 1250
C) 500
D) 1000
If (sales < 5000)
Bonus = 200;
Else if (sales < 7500)
Bonus = 500;
Else if (sales < 10000)
Bonus = 750;
Else if (sales < 20000)
Bonus = 1000;
Else
Bonus = 1250;
A) 750
B) 1250
C) 500
D) 1000
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
38
What will be the value of discountRate after the following statements are executed?
double discountRate = 0.0;
Int purchase = 1250;
Char cust = 'N';
If (purchase > 1000)
If (cust == 'Y')
DiscountRate = 0.05;
Else
DiscountRate = 0.04;
Else if (purchase > 750)
If (cust == 'Y')
DiscountRate = 0.04;
Else
DiscountRate = 0.03;
Else
DiscountRate = 0.0;
A) 0.0
B) 0.04
C) 0.05
D) 0.03
double discountRate = 0.0;
Int purchase = 1250;
Char cust = 'N';
If (purchase > 1000)
If (cust == 'Y')
DiscountRate = 0.05;
Else
DiscountRate = 0.04;
Else if (purchase > 750)
If (cust == 'Y')
DiscountRate = 0.04;
Else
DiscountRate = 0.03;
Else
DiscountRate = 0.0;
A) 0.0
B) 0.04
C) 0.05
D) 0.03
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
39
What will be displayed after the following statements are executed?
int y = 10;
If (y == 10)
{
Int x = 30;
X += y;
System.out.println(x);
}
A) 40
B) 30
C) 20
D) The code contains an error and will not compile.
int y = 10;
If (y == 10)
{
Int x = 30;
X += y;
System.out.println(x);
}
A) 40
B) 30
C) 20
D) The code contains an error and will not compile.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
40
What will be the value of x after the following statements are executed?
int x = 10;
Switch (x)
{
Case 10:
X += 15;
Case 12:
X -= 5;
Break;
Default:
X *= 3;
}
A) 30
B) 20
C) 25
D) 5
int x = 10;
Switch (x)
{
Case 10:
X += 15;
Case 12:
X -= 5;
Break;
Default:
X *= 3;
}
A) 30
B) 20
C) 25
D) 5
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
41
Select all that apply. Which method of the Random class will return a random number within the range of 0.0 and 1.0?
A) nextDouble()
B) nextLong()
C) nextFloat()
D) nextInt(int n)
A) nextDouble()
B) nextLong()
C) nextFloat()
D) nextInt(int n)
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
42
Which of the following statements will create an object from the Random class?
A) randomNumbers() = new Random();
B) Random myNumber = new Random();
C) myNumber = new Random();
D) Random = new randomNumbers();
A) randomNumbers() = new Random();
B) Random myNumber = new Random();
C) myNumber = new Random();
D) Random = new randomNumbers();
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck