CS4A ch.3
Including a space between the relational operators >=, <=, ==, and != causes a syntax error. true false
true
What is 1 + 1 + 1 + 1 + 1 == 5? true false There is no guarantee that 1 + 1 + 1 + 1 + 1 == 5 is true.
true
You can always convert a switch statement to an equivalent if statement. true false
true
Assume x = 4 and y = 5, which of the following is true? !(x == 4) ^ y != 5 x != 4 ^ y == 5 x == 5 ^ y == 4 x != 5 ^ y != 4
x != 4 ^ y == 5
Assume x = 14 and y = 15, Which of the following is true? x % 2 == 0 && y % 2 == 0 x % 2 == 0 && y % 2 == 1 x % 2 == 0 || y % 2 == 0 x % 2 != 0 && y % 2 != 0
x % 2 == 0 && y % 2 == 1 x % 2 == 0 || y % 2 == 0
Given |x - 2| >= 4, which of the following is true? x - 2 >= 4 && x - 2 <= -4 x - 2 >= 4 || x - 2 <= -4 x - 2 >= 4 && x - 2 < -4 x - 2 >= 4 || x - 2 < -4
x - 2 >= 4 || x - 2 <= -4
What is y displayed in the following code? https://snag.gy/vzFwPR.jpg -y is 0. -y is 1 because x is assigned to y first. -y is 2 because x + 1 is assigned to x and then x is assigned to y. -The program has a compile error since x is redeclared in the statement int y = x = x + 1.
y is 2 because x + 1 is assigned to x and then x is assigned to y.
Which of the following expression is equivalent to (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)? year % 4 == 0 && year % 100 != 0 || year % 400 == 0 (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0) (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0) year % 4 == 0 && (year % 100 != 0) || year % 400 == 0
year % 4 == 0 && year % 100 != 0 || year % 400 == 0 (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0) year % 4 == 0 && (year % 100 != 0) || year % 400 == 0
Which of the following is equivalent to x != y? ! (x == y) x > y && x < y x > y || x < y x >= y || x <= y
! (x == y) x > y || x < y
Which of the following expression is equivalent to (x > 1)? x >= 1 !(x <= 1) !(x = 1) !(x < 1)
!(x <= 1)
________ are the boolean operators. (multi) && > ^ !
&& ^ !
________ are short-circuit operators. (multi) && ^ || !
&& ||
Which of the following expressions evaluates to true? 'a' > 'A' 34 > 34 'A' > 'z' 2 > '2'
'a' > 'A'
Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative? (Multi?) 1 < x < 100 && x < 0 ((x < 100) && (x > 1)) || (x < 0) ((x < 100) && (x > 1)) && (x < 0) (1 > x > 100) || (x < 0)
((x < 100) && (x > 1)) || (x < 0)
Which of the Boolean expressions below is incorrect? (multi) (true) && (3 => 4) !(x > 0) && (x > 0) (x > 0) || (x < 0) (x != 0) || (x = 0) (-10 < x < 0)
(true) && (3 => 4) (x != 0) || (x = 0) (-10 < x < 0)
Which of the Boolean expressions below has incorrect syntax? (true) && (3 > 4) !(x > 0) && (x > 0) (x > 0) || (x < 0) (x != 0) || (x = 0)
(x != 0) || (x = 0)
What is the output from System.out.println((int)Math.random() * 4)? 0 1 2 3 4
0
Which of the following is a possible output from invoking Math.random()? 3.43 0.5 0.0 1.0
0.5 0.0
What is y after the following switch statement is executed? https://snag.gy/EaYRGD.jpg 1 2 3 4 0
2
Which of the following operators are right-associative? (multi) * + (binary +) % && =
=
Suppose income is 4001, what is the output of the following code? https://snag.gy/RqZ9sg.jpg no output Income is greater than 3000 Income is greater than 3000 followed by Income is greater than 4000 Income is greater than 4000 Income is greater than 4000 followed by Income is greater than 3000
Income is greater than 3000
Analyze the following code: boolean even = ((231 % 2) == 0); if (even = true) System.out.println("It is even!"); else System.out.println("It is odd!"); The program has a syntax error The program has a runtime error The program displays "It is odd!" The program displays "It is even!"
The program displays "It is even!"
Analyze the following code: if (x < 100) && (x > 10) System.out.println("x is between 10 and 100"); -The statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses. -The statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses and the println() statement must be put inside a block. -The statement compiles fine. -The statement compiles fine, but has a runtime error.
The statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses.
Analyze the following program fragment: https://snag.gy/Yd6igo.jpg The program has a compile error because the required break statement is missing in the switch statement. The program has a compile error because the required default case is missing in the switch statement. The switch control variable cannot be double. No errors.
The switch control variable cannot be double.
In Java, the word true is ________. a Java keyword a Boolean literal same as value 1 same as value 0
a Boolean literal
Suppose cond1, cond2, and cond3 are Boolean expressions. Which of the following expression is equivalent to cond1 || cond2 && cond3 (cond1 || cond2) && cond3 cond1 || (cond2 && cond3)
cond1 || (cond2 && cond3)
A break statement is required for a switch-case statement in Java. true false
false
In a switch statement, the default case must appear last among all cases. Otherwise, it would result in a compilation error. true false
false
The exclusive or (^) of true and true is true. true false
false
You can cast a Boolean value to an int, or an int to Boolean. true false
false
Suppose isPrime is a boolean variable, which of the following is the correct and best statement for testing if isPrime is true? if (isPrime = true) if (isPrime == true) if (isPrime) if (!isPrime = false) if (!isPrime == false)
if (isPrime)
Suppose cond1 and cond2 are two Boolean expressions. When will this if condition be true? in case cond1 is true and cond2 is false in case cond1 is true and cond2 is true in case cond1 is false and cond2 is false in case cond1 is false and cond2 is true
in case cond1 is true and cond2 is true
Analyze the following code: (multi) https://snag.gy/dYJhTg.jpg number is always printed out at least once number is printed out twice if number is zero number is printed out twice if number is negative number is printed out once if number is positive
number is always printed out at least once number is printed out twice if number is zero number is printed out twice if number is negative number is printed out once if number is positive
The ________ operator can be used to compare two values. relational boolean numerical casting
relational
