Java Chapter4A Quiz: Decisions/conditionals

25 July 2022
4.7 (114 reviews)
20 test answers

Unlock all answers in this set

Unlock answers (16)
question
Programs never need more than one path of execution.
answer
false
question
When testing for character values, the switch statement does not test for the case of the character.
answer
false
question
In a switch statement, each of the case values must be unique.
answer
true
question
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.
answer
true
question
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.
answer
false
question
All it takes for an OR expression to be true is for one of the subexpressions to be true.
answer
true
question
All it takes for an AND expression to be true is for one of the subexpressions to be true.
answer
false
question
When testing for character values, the switch statement does not test for the case of the character.
answer
false
question
In an if-else statement, if the boolean expression is false then ________.
answer
the statement or block following the else is executed
question
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;
answer
1000
question
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;
answer
0.0
question
What will be displayed after the following statements are executed? int ans = 10; int x = 65; int y = 55; if (x >= y) { int ans = x + y; } System.out.println(ans);
answer
120
question
The switch statement is a ________.
answer
multiple alternative decision structure
question
The ________ statement is used to create a decision structure which allows a program to have more than one path of execution.
answer
if
question
Which of the following statements determines whether the variable temp is within the range of 0 through 100 (inclusive)?
answer
if (temp >= 0 && temp <= 100)
question
________ works like this: If the expression on the left side of the && operator is false, the expression the right side will not be checked.
answer
Short-circuit evaluation
question
A flag may have the values ________.
answer
true or false
question
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; }
answer
ans = 60, x = 0, y = 50
question
A ________ is a boolean variable that signals when some condition exists in the program.
answer
flag
question
Which of the following is the not equal operator?
answer
!=