Programming Fundamental quiz 1-4
What would be the value of x after the following statements were executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default : x *= 3; }
20
The switch statement is a:
Multiple alternative decision structure
This type of operator determines whether a specific relationship exists between two values
Relational
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 { }
A Boolean expression is one that is either
either true or false
The ________ statement is used to make simple decisions in Java.
if
If chr is a character variable, which of the following if statements is written correctly?
if (chr == 'a')
In an if/else statement, if the boolean expression is false,
the statement or block following the else is executed
What would be the value of discountRate after the following statements are executed?
0.0
Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?
((x > 500 && x < 650) || (y != 1000))
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
The expression tested by an if statement must evaluate to:
true or false
Which of the following expressions will determine whether x is less than or equal to y?
x <= y
What will be the value of bonus after the following code is 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 the value of ans after the following code has been executed? int x = 10; int y = 65; if (x > = y) ans = x + y;
120
What will be the value of x after the following code is executed? int x = 75; int y = 60; if (x > y) x = x - y;
15
What is the value of x after the following code has been executed? int x = 75; int y = 90; if (x ! = y) x += y;
165