chpter three quiz
Java requires that the boolean expression being tested by an if statement be enclosed in ________.
a set of parentheses
Which of the following is the correct boolean expression to test for: int x being a value less than or equal to 500 or greater than 650, or int y not equal to 1000? Question 20 options:
((x <= 500 || x > 650) && !(y == 1000))
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))
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 is the value of x after the following code has been executed? int x = 75; int y = 90; if (x != y) x += y;
165
What will be printed when the following code is executed? double x = 45678.259; System.out.printf("%,.2f", x);
45,678.26
What is the value of ans after the following code has been executed? int x = 35; int y = 20, ans = 80; if (x < y) ans += y;
80
hat does the following code display? int d = 9, e = 12; System.out.printf(%d %d\n", d, e);
9 12
________ operators are used to determine whether a specific relationship exists between two values.
Relational
Which of the following will format 12.7801 to display as $12.78?
System.out.printf("$%,.2f", 12.7801);
Which of the following will format 12.78 to display as 12.8%?
System.out.printf("%.1f%%", 12.78);
an expression tested by an if statement must evaluate to ________.
true or false
In Java, when a character is stored in memory, it is actually the ________ that is stored.
unicode number
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
When testing for character values, the switch statement does not test for the case of the character.
false
When you write a switch statement using arrow case syntax, you must have a break statement in each case section.
false
when two strings are compared using the String class's compareTo method, the comparison is not case sensitive.
false
The switch statement is a ________.
multiple alternative decision structure
If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?
str1.equals(str2)
A local variable's scope always ends at the closing brace of the block of code in which it is declared.
true
All it takes for an OR expression to be true is for one of the subexpressions to be true.
true
If the expression on the left side of the && operator is false, the expression on the right side will not be checked.
true
If you are using a recent version of Java, you can specify multiple values in a case statement.
true
The String.format method works exactly like the System.out.printf method, except that it does not display the formatted string on the screen.
true
________ 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
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
Unicode is an international encoding system that is extensive enough to represent all the characters of all the world's alphabets.
true
a switch expression must have case statements that cover every possible value of the testExpression.
true
the boolean expression in an if statement must evaluate to ________.
true and false.
A flag may have the values ________.
true or False
What does the following code display? double x = 12.3798146; System.out.printf("%.2f\n",x);
12.38
What would be the value of discountRate after the following statements are executed? double discountRate = 0.0;int purchase = 1250; if (purchase > 1000) discountRate = .05;if (purchase > 750) discountRate = .03;if (purchase > 500) discountRate = .01;else discountRate = 0;
.01
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; }
0.0
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 is the value of charges after the following code has been executed? double charges, rate = 7.00; int time = 180; charges = time <= 119 ? rate * 2 : time / 60.0 * rate;
21.00
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); }
40
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;
The code contains an error and will not compile.
What is the value of ans, x, and y after the following statements are executed? int ans = 0, x = 15, y = 25; if ( x >= y) { ans = x + 10; x -=y; } else { ans = y + 10; y += x; }
ans = 35, x = 15, y = 40
If you prematurely terminate an if statement with a semicolon, the compiler will ________.
both not display an error message and assume you are placing a null statement there
A block of code is enclosed in a set of ________.
braces { }
Which of the following expressions determines whether the char variable, chrA, is not equal to the letter 'A'?
chrA != 'A'
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
In the following statement, the switch expression is written correctly. statusType = "Client Error"; yield "Not Found"; default -> statusType = "Unsupported"; yield "Unknown Status"; } ;" style="vertical-align: -4.0px;" />
false
Programs never need more than one path of execution.
false
Which of the following statements determines whether the variable temp is within the range of 0 through 100 (inclusive)?
if (temp >= 0 && temp <= 100)
In an if-else statement, if the boolean expression is false then ________.
the statement or block following the else is executed
If a case section in a switch expression has more than one statement, you must use the ________ keyword to return a value from that case section.
yeild