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