Chapter 3 Flashcards
Analyze the following code.
boolean even = false;
if (even) {
System.out.println(“It is even!”);
}
The code displays It is even!
The code displays nothing.
The code is wrong. You should replace if (even) with if (even == true).
The code is wrong. You should replace if (even) with if (even = true).
The code displays nothing.
Assume x = 4 and y = 5, which of the following is true?
x < 5 && y < 5
x < 5 || y < 5
x > 5 && y > 5
x > 5 || y > 5
x < 5 || y < 5
What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5?
There is no guarantee that 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5 is true.
The __________ method immediately terminates the program.
System.exit(0);
The “less than or equal to” comparison operator in Java is __________.
<=
The equal comparison operator in Java is __________.
==
What is 1 + 1 + 1 + 1 + 1 == 5?
true
Suppose x=10 and y=10. What is x after evaluating the expression (y >= 10) || (x– > 10).
10
What is the output of the following code?
int x = 0; if (x < 4) { x = x + 1; } System.out.println("x is " + x);
x is 1
Which of the following are so called short-circuit operators?
+=
&
||
|
||
Which of the following code displays the area of a circle if the radius is positive.
if (radius != 0) System.out.println(radius * radius * 3.14159);
if (radius >= 0) System.out.println(radius * radius * 3.14159);
if (radius > 0) System.out.println(radius * radius * 3.14159);
if (radius <= 0) System.out.println(radius * radius * 3.14159);
if (radius > 0) System.out.println(radius * radius * 3.14159);
Analyze the following code:
boolean even = false;
if (even = true) {
System.out.println(“It is even”);
}
The program has a compile error.
The program has a runtime error.
The program runs fine, but displays nothing.
The program runs fine and displays It is even.
The program runs fine and displays It is even.
Which of the following is a possible output from invoking Math.random()?
- 43
- 5
- 0
- 0
- 5
0. 0
Assume x = 4, which of the following is true?
!(x == 4)
x != 4
x == 5
x != 5
x != 5
In Java, the word true is ________.
a Boolean literal