Java Programming Chapter 3
If str1 and str2 are both Strings, which of the following expressions will correctly determine whether they are equal?
str1.equals(str2) == 0) or 2 and 3
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, and int y not equal to 1000?
((x<=500 || x > 650) && !(y==1000))
int x = 75; int y = 60; if (x > y) x = x 0 - y;
15
int x = 75; int x = 90; if (x !=y); x +=y;
165
int hours = 45; double pay, payRate = 10.00; pay = hours <= 40? hours * payRate: 40*payRate+(hours-40)* payRate *1.5;
475.00;
An important style rule you should follow when writing if statements is to line up the conditionally executed statement with the if statemen
False
In an if/else statement, if the boolean expression is false,
The statement of block following the else is executed
A local variable's scope always ends at the closing brace of the block of code in which it is declared.
True
because the && operator performs short-circuit evaluation, your boolean expression will usually execute faster if the subexpression most likely false expression is on the left
True
because the || operator performs short-circuit evaluation, your boolean statement will generally run faster if the subexpresson that is most likely to be true is on the left.
True
doube x = 12.3798146; System.out.printf("%d %d\n", d, e);
9 12
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