Java chapter 3.1-3.2
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
The "if" statement is an example of a ___________
Decision structure
The = operator and the == operator perform the same operation
False
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
A block of code is enclosed in a set of
braces, {}
Write an if-else statement that assigns 0 to the variable b and assigns 1 to the variable c if the variable a is less than 10. Otherwise, it should assign -99 to the variable b and assign 0 to the variable c.
if (a < 10) { b = 0; c = 1; } else { b = -99; c = 0; }
Write an if statement that assigns 0.2 to commission if sales is greater than or equal to 100000
if (sales >= 100000) { commission = 0.2; }
Write an if statement that assigns 20 to the variable y and assigns 40 to the variable z if the variable x is greater than 100.
if (x > 100) { y = 20; z = 40; }
Write an if-else statement that assigns 0 to x when y is equal to 10. Otherwise, it should assign 1 to x.
if (y == 10) x = 0; else x = 1;
Write an if-else statement that assigns 1 to x when y is equal to 100. Otherwise it should assign 0 to x.
if (y == 100) x = 1; else x = 0;
Write an if statement that assigns 0 to x when y is equal to 20.
if (y == 20) { x = 0; }
>, <, and == are ___________________
relationship operators
An else clause always goes with _____________
the closest previous if clause that doesn't already have its own else clause.
A flag may have the values
true or false
An expression tested by an if statement must evaluate to
true or false